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 have the following in a .htaccess file:

RewriteCond %{HTTP_HOST} ^www\.aliasdomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^aliasdomain\.com$
RewriteRule ^(.*)$ http://www.maindomain.com/subdir1/subdir2/index.html [R]

In a browser I want aliasdomain.com to access the index.html file and show up as aliasdomain.com.

However it shows up as the full URL as follows: http://www.maindomain.com/subdir1/subdir2/index.html

share|improve this question
up vote 1 down vote accepted

You need to internally rewrite the request in order to keep aliasdomain.com in the browser, and not externally redirect as you are currently doing...

Remove the protocol/host from the RewriteRule substitution, to leave just a root-relative path, and remove the R (redirect) flag. The protocol/host in the substitution forces an external redirect.

RewriteCond %{HTTP_HOST} ^(www\.)?aliasdomain\.com$
RewriteRule ^$ /subdir1/subdir2/index.html [L]

The ^$ pattern in the RewriteRule directive ensures that only requests for the domain root (ie. http://aliasdomain.com/ or http://www.aliasdomain.com/) gets rewritten to the new URL, rather than http://aliasdomain.com/every/possible/url (as mentioned in the comments below).

Since aliasdomain.com is a domain alias of maindomain.com, the entire site is accessible via both domains. They point to the same place. This is what the above rewrite rules are dependent upon. You can't internally rewrite to a different host. So the above RewriteRule serves the file from aliasdomain.com.

share|improve this answer
Oops, thanks for this and I'm sure you are on the right track but I got an "Internal Server Error". – Michael Aug 16 '13 at 7:23
Sorry, yes - a second RewriteCond directive is required in order to prevent a rewrite loop. I've updated the code. – w3dk Aug 16 '13 at 11:00
Thanks again. Now getting the following error: Content Encoding Error The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression. – Michael Aug 16 '13 at 12:44
I'm pretty sure that error is not related to this current issue. Can you access http://aghamore.com/Mayo/Towns/Aghamore/index.html directly in your browser? Are you using Firefox? – w3dk Aug 16 '13 at 13:10
I can access mayo-ireland.ie/Mayo/Towns/Aghamore/Aghamore.htm directly. but not the link you have given. – Michael Aug 16 '13 at 13:50

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.