user527892
user527892

Reputation:

Redirect all traffic to root of another domain

I have a domain that's not to be used anymore. I want to redirect all from http://www.old.com/ to http://www.new.com/, no matter what page the user's attempted to access on www.old.com.

Doing this:

RewriteEngine on
Redirect 301 / http://www.new.com/

is fine for the root, but other pages would do this:

http://www.old.com/cms -> http://www.new.com/cms

whereas I'd want it to go to the root, no matter what.

Upvotes: 46

Views: 72217

Answers (2)

anubhava
anubhava

Reputation: 784918

Put this code in your ROOT .htaccess on www.old.com

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?old\.com$ [NC]
RewriteRule ^ http://www.new.com/ [R=301,L]

This rule will externally redirect all www.old.com/* to www.new.com/

Upvotes: 18

Indrek
Indrek

Reputation: 6696

From http://www.webconfs.com/how-to-redirect-a-webpage.php I'd say you can use the following configuration

Don't redirect subfolders/files (as you wanted): www.example.com/demo/ -> www.newexampledomain.com

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

Redirect to subfolders/files: www.example.com/demo/ -> www.newexampledomain.com/demo/

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

Upvotes: 90

Related Questions