Note –  browsers cache redirects – if you change a redirect and then try again your browser may not be hitting the old domain when you return!!!  Try using temporary redirect code 307 when you debug in place of 301 permanent redirect???

Redirect codes

301 – permanent redirect

307 – Temporary redirect

Redirect from old domain to new domain


RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

or to redirect to the root directory always


RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/ [R=301,L]

Redirect a directory and all sub directories from an old domain to new domain


RewriteEngine on
RewriteBase /mydirectory
RewriteRule (.*) http://www.newdomain.com/mydirectory/$1 [R=301,L]

or to redirect to the root directory always


RewriteEngine on
RewriteBase /mydirectory
RewriteRule (.*) http://www.newdomain.com/mydirectory/ [R=301,L]
Not sure the above is correct, the following worked redirecting a subdirectory from a domain to a new domain

Redirect anything in this directory or any sub directory off it: http://myoldomain.com/api/v100/

To this new domain and new sub directory: http://mynewdomain.com/mynewsubdirectory/api/v100/

This in the root "http://myoldomain.com/".htaccess file worked:


RewriteEngine on
RewriteBase /api/v100/
RewriteRule (.*) http://mydomain.com/mynewsubdirectory/$1 [R=301,L]

But placing it in the .htaccess file in the directory "http://myoldomain.com/api/v100/" instead, this was needed:


RewriteEngine on
RewriteBase /api/v100/
RewriteRule (.*) http://mydomain.com/mynewsubdirectory/api/v100/$1 [R=301,L]

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.