Forum Moderators: phranque
1) abcdef.com
2) qwerty.com
qwerty.com is actually going to be redirected to:
qwerty.abcdef.com as a subdomain
What preg instruction should i implement on my htaccess file in order to accomplish the next examples?
* qwerty.com redirects to qwerty.abcdef.com
* qwerty.com/test redirects to qwerty.abcdef.com/test
* qwerty.com?var=123 redirects to qwerty.abcdef.com?var=123
and so on...
Thanks.
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule .* [domain.com...] [L,R=301]
the first rule is for non www to www
So i think it will work by adding the second rule so you redirect the www to new domain also
~R
# Enable Rewrite options
Options +FollowSymLinks
RewriteEngine on
# Redirect www and non-www on other domain to subdomain over here
RewriteCond %{HTTP_HOST} ^(www\.)?qwerty\.com$ [NC]
RewriteRule ^(.*)$ http://qwerty.abcdef.com/$1 [L,R=301]
# cater for www on sub-domain (just in case it does reesolve) to avoid duplicate content
RewriteCond %{HTTP_HOST} ^www\.qwerty\.abcdef\.com$ [NC]
RewriteRule ^(.*)$ http://qwerty.abcdef.com/$1 [L,R=301]
Rewrite code does exactly what you program it to do... not what you might hope to achieve. Every symbol needs to be carefully checked and you need to cater for all forms of input URL - expected and unexpected.
The code above does not cater for cases where the port number may have been appended, such as if a user looks at your site through a proxy.