Reputation: 45
I'm having trouble redirecting my domain to a subdomain.
My domain is www.example.com and I want all traffic to go to aa.example.com
I tried the following code in htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www?\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php?$ http://new.example.com [R=301,L]
But then this happens:
example.com/aa.example.com
which obviously returns a 'page not found'. I've had a look at similar questions but I'm inexperienced with these things and can't solve the problem.
Upvotes: 1
Views: 61
Reputation: 784918
Use this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://new.example.com%{REQUEST_URI} [R=301,L,NE]
Make sure to test this in a new browser to avoid old browser caches.
Upvotes: 1