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 would like to write a .htaccess rewrite command that takes any url with a subdomain mail and forwards them to whatever domain included that subdomain with /webmail at the end.


mail.zane.com would forward to zane.com/webmail mail.prowebmasters.com would forward to prowebmasters.com/webmail.

In short, I have a master domain with my host with addon domains in folders on the master domain. Any time I type mail.site.com it is forwarding to the index.html of the master site. Instead of doing that I want the sites to open /webmail/ of the site.

share|improve this question

This will work but you'll have to copy the rewrite into each domains .htaccess file.

RewriteCond %{HTTP_HOST} ^mail\.domain\.com$
RewriteCond %{REQUEST_URI} !^/webmail/
RewriteRule (.*) /webmail/$1
share|improve this answer
A few mods, you could make domain.com unecessary in line 1: RewriteCond %{HTTP_HOST} ^mail\..+$ [NC] and for line3 the 301 and last flag: RewriteRule (.*) /mail/$1 [R=301,L] – Anthony Hatzopoulos Jul 31 '12 at 19:47

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.