Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I must have a brain freeze as I can not get my rewrite rules working.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^otherdomain\.example\.com [NC]
RewriteRule ^(.*) http://www.otherdomain.com/ [R=permanent,L]

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{REQUEST_URI} ^/otherdomain [NC]
RewriteRule ^(.*) http://www.otherdomain.com/ [R=permanent,L]

What I want is essential to redirect

otherdomain.example.com and example.com/otherdomain to otherdomain.com

share|improve this question
So .. do they work but incorrectly .. or they do not work at all? Do you have other rules there? DO they work (if you comment those domain redirects)? – LazyOne Apr 19 '12 at 15:03
They are completely ignored. I have removed all other redirects/rewrite stuff from the .htaccess file. – Tom Apr 19 '12 at 19:57
/slap self... My subfolder "otherdomain" contained a .htaccess file that overwrote the one in the root. (I have been trying to upload a complete website mirror "otherdomain.com" to another webhost, so all I would need would be switch DNS incase of webserver troubles at my current webhost.) – Tom Apr 19 '12 at 20:04
I just always thought that .htaccess were handled like this: /.htaccess and then /otherdomain/.htaccess (i.e. so the one in root would always be processed first) – Tom Apr 19 '12 at 20:07
Nope -- global (virtual host) first, then .htaccess; rewriting rules in subfolder will have priority and parent rewriting rules will be ignored unless RewriteOptions directive is used: httpd.apache.org/docs/current/mod/… – LazyOne Apr 19 '12 at 21:34

Just use the below redirection. will work 100%. Because I personally use it for my website....

RewriteCond %{HTTP_HOST} ^subname\.old-main-domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.subname\.old-main-domain\.com$
RewriteRule ^(.*)$ "http\:\/\/www\.newdomain\.com\/$1" [R=301,L]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.