: .htaccess redirect of domain name alias to main domain but must show up as the alias domain I have the following in a .htaccess file: RewriteCond %{HTTP_HOST} ^www.aliasdomain.com$ [OR] RewriteCond
I have the following in a .htaccess file:
RewriteCond %{HTTP_HOST} ^www.aliasdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^aliasdomain.com$
RewriteRule ^(.*)$ 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: www.maindomain.com/subdir1/subdir2/index.html
More posts by @Gloria169
1 Comments
Sorted by latest first Latest Oldest Best
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. aliasdomain.com/ or www.aliasdomain.com/) gets rewritten to the new URL, rather than 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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.