Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change 
notification.

The "RewriteDomainToPath" page has been changed by AndrewNicols:
http://wiki.apache.org/httpd/RewriteDomainToPath

New page:
We recently needed to move several hundred mail domains from standard http
to SSL secured HTTP (HTTPS). To do so, we chose one domain and used
mod_rewrite to redirect to that domain. To make things more complicated, we
also wanted to strip off the first part of the domain name.

As an example, our users were visiting:
{{{
  http://webmail.school.county.sch.uk/
}}}
to access their webmail and
{{{
  http://admin.school.county.sch.uk/
}}}
to access their mail administration interface.

Our softare only requires the
{{{
  school.county.sch.uk
}}}
section of the hostname, and so we needed to redirect to
{{{
  https://new_ssl_host/v/school.county.sch.uk/webmail
  https://new_ssl_host/v/school.county.sch.uk/admin
}}}

Our rewrite rules look something like this:
{{{
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^webmail\.(.*) [NC,OR]
  RewriteCond %{HTTP_HOST} ^mail\.(.*) [NC]
  RewriteRule ^(.*) https://new_ssl_host/v/%1 [R=301,L,QSA]

  RewriteCond %{HTTP_HOST} ^admin\.(.*) [NC,OR]
  RewriteCond %{HTTP_HOST} ^mailadmin\.(.*) [NC,OR]
  RewriteCond %{HTTP_HOST} ^site-admin\.(.*) [NC]
  RewriteRule ^(.*) https://new_ssl_host/v/%1/admin [R=301,L,QSA]
}}}

On the SSL virtual host, we then pick up the hostname with the following
rewrites:
{{{
RewriteEngine On
RewriteRule ^/v/([^\/]+)/admin(.*) /path/to/mail/admin/interface/public_html/$2 
[L,E=SCHOOL_HOST:$1]
RewriteRule ^/v/([^\/]+)(.*) /path/to/our/webmail/interface/$2 
[E=SCHOOL_HOST:$1]

Hope someone finds this useful, it took me a few hours to find the correct
documentation to obtain the HTTP_HOST to use in the RewriteRule.

Reply via email to