Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed Jan 12, 2011 6:13 am 
Offline
Senior Member

Joined: Tue Dec 07, 2010 10:18 am
Posts: 65
Hi,

I want to write a simple serverwide rewrite rule in server so that

http://webmail.domain.com

is redirected to

http://domain.com/webmail

I am using ISPConfig on centos

Thanks
Richard


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 6:20 am 
Offline
Senior Newbie

Joined: Sat Dec 18, 2010 5:45 am
Posts: 11
Code:
<VirtualHost *>
  ServerName webmail.example.com
  RedirectMatch /(.*)$ http://example.com/webmail/$1
</VirtualHost>


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 6:25 am 
Offline
Senior Member

Joined: Tue Dec 07, 2010 10:18 am
Posts: 65
In this case .. I will have to write this for all domains .. I am hosting more then 250 domains...

can there be a generic rule ..?

Rewrite webmail.(.*) $1/webmail


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 2:59 pm 
Offline
Senior Newbie

Joined: Sat Dec 18, 2010 5:45 am
Posts: 11
No generic rule possible AFAIK.


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 3:12 pm 
Offline
Senior Member

Joined: Fri Dec 10, 2010 6:21 am
Posts: 144
There is the ServerAlias directive which allows for associating multiple names (and can have wildcards) with a single VirtualHost section.

http://httpd.apache.org/docs/2.2/mod/co ... erveralias


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.


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 3:22 pm 
Offline
Senior Member

Joined: Fri Dec 10, 2010 6:21 am
Posts: 144
I think something like this may work:

Code:
RewriteCond %{HTTP_HOST} ^webmail\.(.+) [NC]
RewriteRule (.*) http://%1/webmail/$1 [R=301,L]


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 3:51 pm 
Offline
Senior Member

Joined: Tue Dec 07, 2010 10:18 am
Posts: 65
I tried all that ... but just not working


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 4:10 pm 
Offline
Senior Member

Joined: Fri Dec 10, 2010 6:21 am
Posts: 144
richardvc wrote:
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?


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 4:29 pm 
Offline
Senior Member

Joined: Fri Dec 10, 2010 6:21 am
Posts: 144
I ran a quick test and this seems to work fine:

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


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 11:18 pm 
Offline
Senior Member

Joined: Tue Dec 07, 2010 10:18 am
Posts: 65
The redirection works ...

But we get a blank page.

e.g.

http://webmail.dsvtrust.org/ redirects to http://dsvtrust.org/webmail/


If I access the URL in new page, http://dsvtrust.org/webmail/, it works nicely


Top
   
 Post subject:
PostPosted: Wed Jan 12, 2011 11:53 pm 
Offline
Senior Member

Joined: Tue Dec 07, 2010 10:18 am
Posts: 65
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] (2) 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] (3) applying pattern '(.*)' to uri '/'
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230][rid#b883d510/initial] (2) rewrite '/' -> 'http://cjrumao.com/webmail//'
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230][rid#b883d510/initial] (2) 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] (3) 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] (2) 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] (2) 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] (3) 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] (2) rewrite 'http://cjrumao.com/webmail/http://cjrumao.com/webmail//' -> 'http://cjrumao.com/webmail/http://cjrumao.com/webmail/http://cjrumao.com/webmail//'
1


Top
   
 Post subject:
PostPosted: Thu Jan 13, 2011 12:16 am 
Offline
Senior Member

Joined: Tue Dec 07, 2010 10:18 am
Posts: 65
This setting finally worked ..


<VirtualHost *:80>
ServerAlias webmail.*
RewriteEngine On
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 3
RewriteCond %{HTTP_HOST} ^webmail\.(.+) [NC]
RewriteRule (.*) http://%1/webmail/ [R=301,L]
</VirtualHost>


Top
   
 Post subject:
PostPosted: Thu Jan 13, 2011 3:04 am 
Offline
Senior Member

Joined: Fri Dec 10, 2010 6:21 am
Posts: 144
richardvc wrote:
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] (2) 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] (3) applying pattern '(.*)' to uri '/'
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230][rid#b883d510/initial] (2) rewrite '/' -> 'http://cjrumao.com/webmail//'
120.60.138.194 - - [13/Jan/2011:09:15:10 +051800] [webmail.cjrumao.com/sid#b8522230][rid#b883d510/initial] (2) 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] (3) 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] (2) 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] (2) 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] (3) 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] (2) rewrite 'http://cjrumao.com/webmail/http://cjrumao.com/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, right?)

Glad to hear it works, anyway! (But strips any path that was specified? Maybe that's ok?)


Top
   
 Post subject:
PostPosted: Thu Jan 13, 2011 7:05 am 
Offline
Senior Member

Joined: Tue Dec 07, 2010 10:18 am
Posts: 65
Yes, I am okay with removing remaining part of the url ..

My clients will type http://webmail.domain.com

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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group