Adding multiple redirect rules in WordPress .htaccess

The .HTACCESS file is important in Wordpress to manage redirects. You can apply a rule inside this file in case you changed your blog address, moved to www, moved to non www or changed permalinks.

Redirect All to HTTPS:// NON WWW

If you want to move all users to https://yoursite.com Use the following rules.

RewriteEngine on
# Redirect www to non-www first 

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,NE,L]

# Then redirect http to https (if necessary)
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]

This will redirect http, http www, https www to https:// (without www). 

lifehacker.com follos this rule.

Redirect ALL to HTTPS (non-www) with traling slash


To redirect all users to https:// non www and with trailing slash

RewriteEngine on
# Redirect www to non-www first 

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,NE,L]

# Then redirect http to https (if necessary)
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
  
# Adding slash (if required)
RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

howtogeek.com follows this rule.

First hold your breath and know what do you need.


Take this example, you can to redirect all your traffic to https://www. you can simple do by
1. Redirecting non www to www (HTTP)
2. Redirect HTTP traffic to HTTPS.

Don't use.
1. redirect http to https
2. non www to www
3. https (non www) to https www

More redirect rules may end up infinite redirest and won't load the page. In chrome you'll get ERR_too_much_redirects.

If you can do things in two rules, why bother adding more?

Similliarly to redirect all traffic to https (non www) you can use this simple approch.

COMMENTS

Name

Basics,5,blog,2,Guides,2,Lineage-OS,12,News,1,Tech Blog,1,Wordpress,1,
ltr
item
Devendra Meena's Personal Biased Blog: Adding multiple redirect rules in WordPress .htaccess
Adding multiple redirect rules in WordPress .htaccess
Devendra Meena's Personal Biased Blog
https://www.devendrameena.com/2018/02/adding-multiple-redirect-rules-in-wordpres-htaccess.html
https://www.devendrameena.com/
https://www.devendrameena.com/
https://www.devendrameena.com/2018/02/adding-multiple-redirect-rules-in-wordpres-htaccess.html
true
5173367778006439255
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share. STEP 2: Click the link you shared to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy