tags:

views:

25

answers:

1

I recently got an alternate domain (parked) and would like it to behave like this:

  • on a request for "alt-domain.com/" (root): serve "main-domain.com/fakeroot" without a redirect (200)
  • on a request for "alt-domain.com/anyotherpage": serve "main-domain.com/anyotherpage" with a redirect (301)

I tried this, but it doesn't work:

RewriteCond %{HTTP_HOST} ^(www\.)?alt-domain\.com$ [NC] 
RewriteCond %{REQUEST_URI} ^/$ 
Rewriterule ^(.)$ /fakeroot.php  [L]

RewriteCond %{HTTP_HOST} ^(www\.)?alt-domain\.com [NC] 
RewriteCond %{REQUEST_URI} !^/$ 
RewriteRule ^(.*)$ http://www.main-domain.com/$1 [L,R=301]

Each rule works on its own, but when both are present the request for root also get a redirect. I tried inverting the order, tried skipping [S=1], tried [NS], but no luck. That's when I realized I'm not an htaccess expert, nor a regex expert.

Any help would be much appreciated.

D.

A: 

The problem is that the L flag probably doesn't work like you expect, and when mod_rewrite re-examines your rules, RewriteCond %{REQUEST_URI} !^/$ matches because the %{REQUEST_URI} is updated to /fakeroot.php after the initial rewrite.

There are a few different ways to fix this, but I believe this should work well enough, and it doesn't involve changing much:

RewriteCond %{HTTP_HOST} ^(www\.)?alt-domain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$ 
Rewriterule ^(.)$ /fakeroot.php  [L]

RewriteCond %{HTTP_HOST} ^(www\.)?alt-domain\.com [NC] 
RewriteCond %{REQUEST_URI} !^/(fakeroot\.php)?$
RewriteRule ^(.*)$ http://www.main-domain.com/$1 [L,R=301]
Tim Stone
I couldn't make it work, even when all looks fine when looking at it. I ended up redirecting all except the root with htaccess, and using the homepage code to serve different content when the alternate domain is detected.Thanks for your help
Deg