views:

70

answers:

2

I'm trying to redirect one domain to the root and another to a directory. The problem I'm having is the second domain is overwriting the firsts redirection.

Here is what I have.

RewriteEngine On
RewriteCond %{HTTP_HOST}  !^http://example.site.net$ [NC]
RewriteCond %{REQUEST_URI} !^/.*$
RewriteRule ^(.*)$  / [L]

RewriteEngine On
RewriteCond %{HTTP_HOST} !^http://example2.com [NC]
RewriteCond %{HTTP_HOST} !^http://www.example2.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI} !^/example2_directory/
RewriteRule ^(.*)$ /example2_directory/$1   
+1  A: 

That's because 'example2.com' and 'www.example2.com' are not 'example.site.net', like your .htaccess rule states...

If you want those rules to apply to those specific domains, you need to remove the '!' in front of them. Otherwise you need to explain what specific domains need to point to what, not just 'one domain' and 'the other domain'.

Edit: Also, you're not supposed to include the 'http://' for your HTTP_HOST conditions.

animuson
+1  A: 

I think you might not realize you're negating your comparisons with "!"

Also, you dont' have to turn the engine on twice.

Try this:

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^http://example.site.net$ [NC]
RewriteCond %{REQUEST_URI} !^/.*$
RewriteRule ^(.*)$  / [L]

RewriteCond %{HTTP_HOST} ^http://example2.com [NC]
RewriteCond %{HTTP_HOST} ^http://www.example2.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI} !^/example2_directory/
RewriteRule ^(.*)$ /example2_directory/$1  
UltimateBrent