Mobile app version of vmapp.org
Login or Join
Gloria169

: .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

@Gloria169

Posted in: #Apache #Domains #Htaccess #Redirects #UrlRewriting

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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Gloria169

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme