views:

96

answers:

3

I have the script:

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

Rewrite rule to redirect /old to /new

RewriteCond %{REQUEST_URI} ^/old$
RewriteRule   . /new [L,R=301]

Which will redirect http://example.com to http://www.example.com, but would like this script to work the same if a user requests the URL via HTTPS? I can't seem to find a solution anywhere.... =/

Anyone have any ideas?

Thanks

A: 

Use this rule:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.example.com%{REQUEST_URI} [L,R=301]
Gumbo
This didn't work... It doesn't seem to detect SSL
1nsane
A: 
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

RewriteCond %{HTTPS} =off
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
ceejayoz
this didn't work either... same reason as above :(
1nsane
+1  A: 

It appears that this can't be done in our case.... apparently because the certificate must first be accepted by the browser. In the event that it is not accepted, the redirect will not be allowed to occur because of the browser's "warning" message.

http://www.webhostingtalk.com/showthread.php?t=885150

1nsane
HTTP is HTTP over SSL. So the SSL connection has to be established before the HTTP request can be sent. So, yes, the certificate has to be accepted before a HTTP redirect can happen.
Gumbo
"We're not using an accepted SSL certificate" would've been relevant information. It changes the question quite a bit
ceejayoz
The purpose of the question was to mitigate the issue of not having a certificate for domain.com and only for www.domain.com - but we've now figured out that this won't work as mentioned above.
1nsane