1

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.

erkin
  • 535
  • 1
  • 5
  • 11

3 Answers3

0

Try adding this rule:

RewriteCond %{HTTP_HOST} ^(bar|foo)\.com/? [NC]
RedirectRule ^(.*)$ http://www.bar.com$1 [L,R=301]
marapet
  • 54,856
  • 12
  • 170
  • 184
0

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

akushwaha
  • 21
  • 2
0

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]
Mordor
  • 485
  • 2
  • 4
  • 14