Forum Moderators: phranque
RewriteEngine On
RewriteCond %{HTTP_HOST} "!^subdomain\.mysite\.com"
RewriteRule (.*) [mysite.com...] [R=301,L]
you should remove the double quotes from the condition pattern.
and [...] would not work, because this is an invalid URL.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^subdomain\.mysite\.com
RewriteRule ^(.*) http://www.mysite.com/$1 [R=301,L] If you cannot access your subdomain from your root domain (e.g. subdomain points to subfolders of the domain or is completely out of the space of the root domain), you have to place the .htaccess into the document root of the subdomain.
Remember that the [R]-Flag forces an external redirect, the displayed URL in the browser's location bar would change.
explicitly forced redirect!= internal redirect
If you'd like to keep the URL, you've to use mod_rewrite in combination with mod_proxy (proxy-pass). Simply change the flag from
[R=301,L] [P,L] Rob
# Turn the rewrite engine on
RewriteEngine On
# IF the requested host *IS NOT* subdomain.mysite.com
RewriteCond %{HTTP_HOST} !^subdomain\.mysite\.com
# then redirect to www.mysite.com
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
To fix it, you need to remove the "!" negation oprerator:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mysite\.com
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
If it appears that this code is never executed, check your server error log. It may contain an error message telling you that you need to enable SymLinks, which is required by mod_rewrite. If so, add the line
Options +FollowSymLinks just before the code shown above.