You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Rudi Kramer <ru...@gmail.com> on 2010/11/15 10:08:07 UTC

[users@httpd] Mod-rewrite problem

Hi,

I am using ubunto 8.0.4 and apache 2.2.8 and I'm having some issue with mod
rewrite and SSL redirection.

I have two objectives. The first is to redirect
http://www.site.co.za<https://www.site.co.za/>
 and http://site.co.za <https://www.site.co.za/>  to the url
https://www.site.co.za and the second is to redirect all traffic for
https://site.co.za to https://www.site.co.za.

I can get the first part working perfectly using the following:

<VirtualHost www.site.co.za:80 <http://site.co.za/>>
ServerName www.site.co.za
ServerAlias site.co.za
DocumentRoot /var/www/site.co.za
ErrorLog /var/log/apache2/site.co.za.co.za-error_log
CustomLog /var/log/apache2/site.co.za-access_log common

RewriteEngine   on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.site.co.za%{REQUEST_URI}
RewriteLog /var/log/apache2/site.co.za-rewrite_log
RewriteLogLevel 3
</VirtualHost>

But for the life of me I cannot get the second part working, I've tried of
this:

<VirtualHost www.site.co.za:80 <http://www.site.co.za/>>
...
RewriteEngine   on
RewriteCond %{HTTPS} on
RewriteRule (.*) https://www.site.co.za%{REQUEST_URI}
RewriteLog /var/log/apache2/site.co.za-rewrite_log
RewriteLogLevel 3

RewriteEngine   on
RewriteCond %{SERVER_PORT} ^443$
RewriteRule (.*) https://www.site.co.za%{REQUEST_URI}
RewriteLog /var/log/apache2/site.co.za-rewrite_log
RewriteLogLevel 3
</VirtualHost>

and this:

<VirtualHost www.site.co.za:443>
...
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteLog /var/log/apache2/ssl-site.co.za-rewrite_log
RewriteLogLevel 3
</VirtualHost>

I've even add this to the .htaccess file in  /var/www/site.co.za  but still
no joy:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteLog /var/log/apache2/ssl-site.co.za-rewrite_log

For some strange reason mod-rewrite seems to be ignoring the SSL traffic
even when I remove all rules except for the SSL https://site.co.za to
https://www.site.co.za rewrite rule and when I tryhttps://site.co.za I get
nothing in the rewrite log files.

Any ideas?

Thanks