...

View Full Version : RewriteCond for SSL



Maurizio1230
07-16-2010, 10:13 PM
Hi all,
I set some RewriteCond in order to redirect from some pages (80 port) to its corresponding ssl pages (443):

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} /LogIn.php
RewriteRule ^(.*)$ https://site.com/LogIn.php [R,L]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} /ok.php
RewriteRule ^(.*)$ https://site.com/ok.php [R,L]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} /ko.php
RewriteRule ^(.*)$ https://site.com/ko.php [R,L]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} /bho.php
RewriteRule ^(.*)$ https://site.com/bho.php [R,L]

Is it possible to sum/summarize them in less lines?

After that, is it possible to redirect from all ssl pages, that aren't listed above, to its corresponding non-ssl page?

Thank you very much

abduraooft
07-17-2010, 08:34 AM
Is it possible to sum/summarize them in less lines?
Try
RewriteCond %{REQUEST_URI} ^/(LogIn|ok|ko|bho)\.php$
RewriteRule ^(.*)$ https://site.com/$1 [R,L]

Inigoesdr
07-17-2010, 06:19 PM
Try
RewriteCond %{REQUEST_URI} ^/(LogIn|ok|ko|bho)\.php$
RewriteRule ^(.*)$ https://site.com/$1 [R,L]

You need to specify the port or it will start an infinite loop when someone goes to the HTTPS site.

Maurizio1230, try this out:

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/(LogIn|ok|ko|bho)\.php$
RewriteRule ^(.*)$ https://site.com/$1 [R,L]

RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/(LogIn|ok|ko|bho)\.php$
RewriteRule ^(.*)$ http://site.com/$1 [R,L]

Maurizio1230
07-17-2010, 07:49 PM
Thank you very much
And what about my second question?:

is it possible to redirect from all ssl pages, that aren't listed above, to its corresponding non-ssl page?

Inigoesdr
07-18-2010, 03:23 PM
Thank you very much
And what about my second question?:

Unless I'm misunderstanding you, that should be covered with the second rewrite I posted above.

Maurizio1230
07-18-2010, 05:21 PM
Oh. thank you very much. Sorry but I didn't see the not Logical Operator "!" in your code. You are great!!! :)
May I ask you how to redirect from http://site.com/blabla/EVERYTHING.php to https://site.com/blabla/EVERYTHING.php? It should be included in the .htaccess where I added the above code.

I try to do it in this way but it doesn't work:

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/(LogIn|ok|ko|bho)\.php$
RewriteCond %{REQUEST_URI} ^/blabla/^.*$
RewriteRule ^(.*)$ https://site.com/$1 [R,L]


I use ^.*$ because ^.*$ means matching everything.

Thank you very much inigiesdr.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum