[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Apache2 & mod_rewrite



On Sat, Sep 17, 2005 at 06:47:12PM +0200, Marco wrote:
> OK. Apache2 works perfectly now. Thanks :-)
> 
> I have also an other question to the rewrite module and Apache2. I have 
> configurated a virtual host with ssl.
> I would like all connection to "https://*.domain.com"; are rewritten to 
> "http://www.domain.com"; except for
> all connection to "https://*.domain.com/webmail"; that they must be 
> concurred.
> 
> ex. https://pop.domain.com --> http://www.domain.com
>     https://domain.com --> http://www.domain.com
>     https://www.domain.com/webmail --> https://www.domain.com/webmail
>     https://domain.com/webmail --> https://www.domain.com/webmail
>     https://pop.domain.com/webmail --> https://www.domain.com/webmail
> 
> This also for the other domains (domain1.com, domain2.com ecc.)
> 
> Can you help me again??
> 
> Thanks
> 
> Marco

Hi Marco,

I haven't used rewriting in SSL-servers, but it should work like this:

	RewriteEngine On
	RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
	RewriteCond %{REQUEST_URI} !^/webmail [NC] 
	RewriteCond %{HTTP_HOST} !^$
	RewriteRule ^/(.*) http://www.domain.com/$1 [L,R]
	RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
	RewriteCond %{REQUEST_URI} ^/webmail [NC] 
	RewriteCond %{HTTP_HOST} !^$
	RewriteRule ^/(.*) https://www.domain.com/$1 [L,R]

With these rules, if you have your SSL virtual hosts separate from your
non-SSL virtual hosts, add those lines to your SSL virtual hosts. Then
http://anything.domain.com/webmail would go to the
http://www.domain.com/webmail, so that might still need special handling
depending on how you want it handled. If you want
http://anything.domain.com/webmail to go to the
https://www.domain.com/webmail then you need to add another rule in
addition to the ones in your non-SSL virtual hosts that are working
right now (before them):

	RewriteCond %{REQUEST_URI} ^/webmail [NC] 
	RewriteRule ^/(.*) https://www.domain.com/$1 [L,R]


If on the other hand you have your SSL virtual hosts in the same virtual
hosts as your non-SSL virtual hosts, replace the rules which are working
right now with the rules above. The
http://anything.domain.com/webmail would then go to the
https://www.domain.com/webmail. To make the
http://www.domain.com/webmail to go to the
https://www.comain.com/webmail, add those two lines before the other
rules.

If you want only https requests to go to the SSL virtual host, then you
can use:

	RewriteCond %{HTTPS} ^on$

to check if the request is https or not.

So once again, depending on your setup and how you want those http vs.
https cases handled, there are a few possibilities :)

Simo
-- 
:r ~/.signature

Attachment: signature.asc
Description: Digital signature


Reply to: