Server Fault is a question and answer site for system and network administrators. 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 have 2 domains that point to the same IP and

I don't have access to setting up a virtual host for the domains but I have managed to create .htaccess rules so that it is setup like this.

  • points to / directory
  • points to /bar directory

Having the setup above now I could have different index.html files for accessing the root of the domain.

This is the rule I implemented for

RewriteCond %{HTTP_HOST} ^(www\.)?bar\.com$
RewriteCond %{REQUEST_URI} !bar/
RewriteRule ^(.*)$ bar/$1 [L]

The above rule works perfectly however when I navigate to it doesn't give me a 404 but instead it still points to the root of my bar directory.

So, I created another RewriteCond to handle such issue.

RewriteCond %{HTTP_HOST} ^(www\.)?bar\.com$
RewriteCond %{THE_REQUEST} "(GET|POST) \/bar\/ HTTP/"

While the RewriteCond works perfectly. I am not sure what rewrite rule I would write so that when the user visits it would point to the /bar/bar directory and thus would give me a 404

I tried the RewriteRule below but it doesn't seem to work

RewriteRule ^bar/(.*)$ bar/bar/$1  [L,QSA]

So I temporarily created a redirect to the main domain.

RewriteRule ^bar/(.*)$$1 [L,QSA,R=301]
share|improve this question

This is how I did it.

RewriteCond %{HTTP_HOST} ^(www\.)?bar\.com$
RewriteCond %{THE_REQUEST} "(GET|POST) \/bar\/(.*) HTTP/"
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(.*)$ /bar/$1 [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.