Nate
Nate

Reputation: 28384

Rewrite not working when "www" in URL

I used to have a website at www.roboticsguy.com, which I moved over to www.foxytronics.com. I want to redirect all requests from the old site to the new one. Here is my .htaccess file:

Options +FollowSymlinks
RewriteEngine on

redirect / http://www.foxytronics.com

rewritecond %{http_host} ^roboticsguy.com [nc]
rewriterule ^(.*)$ http://www.foxytronics.com/$1 [r=301,nc] 

This URL works:

roboticsguy.com/test/

This one doesn't:

www.roboticsguy.com/test/

What's the problem with the rewrite and how should I fix it?

Upvotes: 0

Views: 21

Answers (1)

ceejayoz
ceejayoz

Reputation: 180024

The line rewritecond %{http_host} ^roboticsguy.com [nc] means "only do the next bit if the domain name is roboticsguy.com". www.roboticsguy.com is not the same as roboticsguy.com.

rewritecond %{http_host} ^roboticsguy.com [nc]
rewriterule ^(.*)$ http://www.foxytronics.com/$1 [r=301,nc] 
rewritecond %{http_host} ^www.roboticsguy.com [nc]
rewriterule ^(.*)$ http://www.foxytronics.com/$1 [r=301,nc]

or

rewritecond %{http_host} ^(www.)?roboticsguy.com [nc]
rewriterule ^(.*)$ http://www.foxytronics.com/$1 [r=301,nc] 

should work.

Upvotes: 1

Related Questions