1
votes

I would like to redirect all users who visit pages on my old domain to the same page on my new domain (only the domain name is changing).

If my old domain is www.OLDDOMAIN.com and my new domain is www.NEWDOMAIN.com then I want to be able to redirect visitors who visit www.OLDDOMAIN.com/c/123/Page-Name to www.NEWDOMAIN.com/c/123/Page-Name (note that these are SEO friendly URLs and not simply sub directories or filenames)

However, I do not want this rule to apply to visitors from a certain IP addresses (lets say 2 IP address 123.123.123.123 and 345.345.345.345 - I appreciate these aren't valid).

I would also like to ensure that all subdomains e.g. files.OLDDOMAIN.com are NOT redirected to files.NEWDOMAIN.com

AND I would like the ability to add exclusions to this rule. E.g. I want to continue to be able to access www.OLDDOMAIN.com/index.php or a subfolder e.g. www.OLDDOMAIN.COM/admin/

The reason for need to do this is the website currently on www.OLDDOMAIN.com is being moved to www.NEWDOMAIN.com. and www.OLDDOMAIN.com is being repurposed for another website. The reason I need the redirects is to retain search engine rankings, at least until the new site is established. The solution therefore needs to be SEO friendly.

Apologies in advance for not supplying any code but I'm not entirely sure where to start with this one...

1

1 Answers

1
votes

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

# exclude these IPs
RewriteCond %{REMOTE_ADDR} !^(123\.123\.123\.123|345\.345\.345\.345)$

# exclude these URIs
RewriteCond %{REQUEST_URI} !^/(/index\.php|admin/) [NC]

# exclude sub-domains
RewriteCond %{HTTP_HOST} ^(www\.)?OLDDOMAIN\.com$ [NC]

# redirect to new host
RewriteRule ^ http://www.NEWDOMAIN.com%{REQUEST_URI} [R=302,L,NE]