Reputation: 1086
Due to a server migration, I'm attempting to direct all URI's starting with /rc
, /roundcube
, /sm
, or /squirrelmail
to https://webmail.{HTTP_HOST}
using the following mod_rewrite code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteCond %{REQUEST_URI} ^/(rc|roundcube|sm|squirrelmail)(\/)?(.*)?$
RewriteRule ^/(.*) https://webmail.%1 [R=302, L]
Because I want this redirection to affect all virtual hosts on the machine, I'm putting it in the virtual host directive inside the httpd.conf file of Apache.
The server does have mod_rewrite enabled, but this above seems to do nothing at all!
Perhaps someone can spot my error?
An example of the intended result is:
http://www.mydomain.com/rc --> https://webmail.mydomain.com
It should be able to handle the task with or without the www
or the trailing /
and maybe parameters included when users bookmarked the original URL.
Upvotes: 1
Views: 171
Reputation: 143906
I think if you simply put that in the httpd.conf file, there is no context for the rule. Try wrapping it in a location or directory (location probably better):
<Location "/">
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(rc|roundcube|sm|squirrelmail)(/)?(.*)?$
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteRule ^/(.*) https://webmail.%2 [R=302,L]
</Location>
and get rid of the space after R=302,
Upvotes: 1