Rewrite rule: webmail.domain.com to domain.com/webmail
I want to write a simple serverwide rewrite rule in server so that
is redirected to
I am using ISPConfig on centos
Thanks
Richard
13 Replies
````
can there be a generic rule ..?
Rewrite webmail.(.*) $1/webmail
While it does allow for wildcards, I have personally only ever used a leading wildcard (eg *.example.com), but I'd have a look at that at least to see if it can solve your issue together with the appropriate rewrite rules.
RewriteCond %{HTTP_HOST} ^webmail\.(.+) [NC]
RewriteRule (.*) http://%1/webmail/$1 [R=301,L]
@richardvc:
I tried all that … but just not working
Can you elaborate a bit on how it doesn't work?
What exactly have you done and what happens?
<virtualhost *:80="">ServerAlias webmail.*
RewriteEngine On
RewriteCond %{HTTP_HOST} ^webmail\.(.+) [NC]
RewriteRule (.*) http://%1/webmail$1 [R=301,L]</virtualhost>
Of course, with the rewrite rules there you do not technically need a specific VirtualHost for this task, but I think it's kind of nice in case you ever want any other configuration specific to these hosts.
(As for the removed slash in the rewriterule compared to what I originally suggested, it's to avoid getting double slashes in the destination url, it didn't really break anything but looked bad.)
But we get a blank page.
e.g.
If I access the URL in new page,
rewrite log …
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial init rewrite engine with requested uri /
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial applying pattern '(.*)' to uri '/'
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial rewrite '/' -> '
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial explicitly forcing redirect with
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial applying pattern '(.*)' to uri '
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial rewrite '
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial explicitly forcing redirect with
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial applying pattern '(.*)' to uri '
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial rewrite '
1
RewriteEngine On
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 3
RewriteCond %{HTTP_HOST} ^webmail.(.+) [NC]
RewriteRule (.*) http://%1/webmail/ [R=301,L]
@richardvc:
It is going in infinite loop …
rewrite log …
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial init rewrite engine with requested uri /
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial applying pattern '(.*)' to uri '/'
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial rewrite '/' -> '
http://cjrumao.com/webmail// '120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial explicitly forcing redirect with
http://cjrumao.com/webmail// 120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial applying pattern '(.*)' to uri '
http://cjrumao.com/webmail// '120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial rewrite '
http://cjrumao.com/webmail// ' -> 'http://cjrumao.com/webmail/http://cjrumao.com/webmail// '120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial explicitly forcing redirect with
http://cjrumao.com/webmail/http://cjrumao.com/webmail// 120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial applying pattern '(.*)' to uri '
http://cjrumao.com/webmail/http://cjrumao.com/webmail// '120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230]rid#b883d510/initial rewrite '
http://cjrumao.com/webmail/http://cjrumao.com/webmail// ' -> '' http://cjrumao.com/webmail/http://cjrum … /webmail//">http://cjrumao.com/webmail/http://cjrumao.com/webmail/http://cjrumao.com/webmail// 1
Without knowing what the configuration looked like when this happened it's very hard to point out the problem (but it's clear that it was not http://forum.linode.com/viewtopic.php?t=6538#35400
Glad to hear it works, anyway! (But strips any path that was specified? Maybe that's ok?)
My clients will type
Thank you for your help .. this type of setup is requested many times on ISPConfig forum .. but no body was able to handle it because the way ISPConfig works … I will prepare a simple FAQ there ..
Richard