user2102471
user2102471

Reputation: 11

I'm totally baffled... how do i redirect to both www an non www to a new domain?

I've recently moved domains successfully however what I didn't realise was that there were two versions of the website: www and non-www

I want to redirect the traffic from my non-www site to my new domain...

This is how the iirf.ini file looks like at the moment:

RewriteCond %{HTTP_HOST} ^www\.foo\.com/? [NC]
RedirectRule ^(.*)$ http://www.bar.com$1 [L,R=301] 

How do I set it up so that it also redirects the non-www site?

Please help because I'm baffled.

Upvotes: 1

Views: 134

Answers (3)

Mordor
Mordor

Reputation: 485

You can't redirect both versions in one statement. Well, you probably "could", but it's not the correct way how to do this. Correct way is this:

1) Redirect old domain from www to non-www version (do this in .htaccess file belonging to an old domain)

2) Redirect new domain from www to non-www version (do this in .htaccess file belonging to a new domain)

3) Redirect old non-www version of the old domain to a new non-www version of new domain (do this in .htaccess file belonging to an old domain)


So here is the drill:

1) This redirects old domain from www to non-www:

RewriteCond %{HTTP_HOST} ^www.olddomain.com [nc]
RewriteRule (.*) http://olddomain.com/$1 [R=301,L]

2) This redirects new domain from www to non-www:

RewriteCond %{HTTP_HOST} ^www.newdomain.com [nc]
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]

3) This redirects old domain to new domain (both non-www versions):

RewriteCond %{HTTP_HOST} ^olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,QSA,L]

Upvotes: 0

akushwaha
akushwaha

Reputation: 21

Network Level Solution: 1. Point your external DNS to same public IP of www domain, so that both domains point to same IPs.

eg. www.abc.com - 111.111.111.111 adb.com - 111.111.111.111

Upvotes: 0

marapet
marapet

Reputation: 56486

Try adding this rule:

RewriteCond %{HTTP_HOST} ^(bar|foo)\.com/? [NC]
RedirectRule ^(.*)$ http://www.bar.com$1 [L,R=301]

Upvotes: 0

Related Questions