How to load the load on forwarding rules using a rule that captures everything for everything else. NOT suitable for backpress for wordpress for apache htaccess

What is needed

  • oldwebsite.com/about and oldwebsite.com/about/ go to newwebsite.com/about
  • oldwebsite.com and oldwebsite.com/ go to newwebsite.com
  • oldwebsite.com/wp-admin remains as I need to access the Wordpress beta server
  • oldwebsite.com/everything-else go to newwebsite.com/blog/everything-else

What i tried

I used Redirect 301 ... for requirements of 1st 2.

They work well.

What happened

Then when i added

 RewriteRule !^wp-admin($|/) http://newwebsite.com/blog%{REQUEST_URI} [L,R=301] 

from elsewhere for 3 and 4

This does not work when I tried to access wp-admin as it redirects to newwebsite.com/blog/wp-login.php......

0
redirect apache wordpress .htaccess
Feb 16 '16 at
source share
1 answer

Key point 1

I should use the L flag to make sure that as soon as the rule matches, it will exit htaccess .

Key point 2

WordPress relies on many files and subfolders for the backend. You must use the regular expression (wp\-.*) To catch all the scripts.

Code with comments

 # when whatever comes after oldwebsite.com/ matches about OR about/ # go to ... # the L makes sure once this rule matches, stop checking the rest. # the 301 is for the redirection status code which is good for SEO # read https://moz.com/learn/seo/redirection RewriteRule ^about($|/) http://newwebsite.com/about [R=301,L] # same treatment for the index page RewriteRule ^($|/) http://newwebsite.com [R=301,L] # when whatever comes after oldwebsite.com/ AND does NOT match wp-{wildcard here....} # take that whatever and append to http://newwebsite.com/blog/ # and then redirect there using status code 301 and if this rule is true, stop any further RewriteRule !^(wp\-.*) http://newwebsite.com/blog%{REQUEST_URI} [R=301,L] 
+1
Feb 16 '16 at
source share



All Articles