Reputation: 1
One of the search engines has spidered my test site: new.mydomain.co.uk
and now I have finished testing, I want to redirect these URL's to my main site which uses the same extensions.
Example:
new.mysite.co.uk/thispage/
needs to point to www.mysite.co.uk/thispage
and so on. I have searched and found a solution (copied below) that I though would achieve my objective, but this cause just points the 'test site' to www.mysite.co.uk
rather than the extensions.
This is the code I have used:
RewriteCond %{HTTP_HOST} ^new\.mysite\.co.uk$ [NC]
RewriteRule ^(.*) http://www.mysite.co.uk/$1 [L,R=301]
I have spent a few hours trying to work out what I have done wrong, but having exhausted my own research, I need to ask the experts to help me resolve this issue.
Many thanks
Upvotes: 0
Views: 54
Reputation: 3972
I would suggest instead of inside .htaccess, do it in your proper Apache virtual host configuration. Something like this will redirect all traffic on new.mysite to www.mysite with correct paths appended:
<VirtualHost *:80>
ServerName new.mysite.co.uk
Redirect permanent / http://www.mysite.co.uk/
</VirtualHost>
If you just include the "Redirect" line this should work for your .htaccess file as well if you do not want to edit the apache files directly. (Unless your new. and www. share the same physical folder)
A more complicated Rewrite rule could be similar to what you suggested:
RewriteCond %{HTTP_HOST} ^new\.mysite\.co\.uk
RewriteRule ^(.*)$ http://www.mysite.co.uk/$1 [R=301,L]
With a backslash before .uk
Ps. this question is more suitable at serverfault.com
Upvotes: 1