Showing results for 
Search instead for 
Did you mean: 

.htaccess 301 redirects not working properly


.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 to


It needs to work in such a way that for example redirects to and so on.


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


I tried this:

RewriteEngine On

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

Also this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC,OR]
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$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


Re: .htaccess 301 redirects not working properly

Well... this worked:


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

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