0

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

5
  • 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, 2012 at 15:03
  • They are completely ignored. I have removed all other redirects/rewrite stuff from the .htaccess file.
    – Tom
    Apr 19, 2012 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, 2012 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, 2012 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, 2012 at 21:34

1 Answer 1

1

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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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