cancel
Showing results for 
Search instead for 
Did you mean: 

.htaccess 301 redirects not working properly

SOLVED

.htaccess 301 redirects not working properly

I just moved my Magento site to a new domain, the URL structure is unchanged so in order to preserve SEO I want to set up a global 301 redirect from oldsite.com to newsite.com.

 

It needs to work in such a way that for example oldsite.com/product1 redirects to newsite.com/product1 and so on.

 

I found many suggestions, but no matter which code I use, oldsite.com/product1 always redirects to the main domain newsite.com, without the rest of the URL.

 

I tried this:

RewriteEngine On

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

Also this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]

Both versions only seem to redirect to the main domain, even though they are supposed to preserve the whole URL structure. Where am I going wrong? Thanks

1 REPLY

Re: .htaccess 301 redirects not working properly

Well... this worked:

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.newsite.com$ [NC] 
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]
</IfModule>

Don't know why, might be to do with the fact that I added www to the redirect URL. Anyway, all sorted.