Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

mod_rewrite SSL Redirection
Welcome, Guest. Please login or register.
December 02, 2008, 12:43:49 PM
11304 Posts in 1248 Topics by 498 Members
Latest Member: katCheeme
Experts Round Table Network  |  Webservers  |  Apache  |  mod_rewrite SSL Redirection « previous next »
Pages: [1]
Author Topic: mod_rewrite SSL Redirection  (Read 650 times)
CrYpTiC_MauleR
Site Builder

Offline Offline

Posts: 489



WWW
« on: July 07, 2007, 03:40:12 PM »

Code:
RewriteCond  %{SERVER_PORT} !^443$
RewriteRule ^(contact|login)/$ https://%{SERVER_NAME}/$1/ [R,L]

RewriteCond  %{SERVER_PORT} ^443$
RewriteCond  %{REQUEST_URI} !^(contact|login)/$
RewriteRule ^([a-z]+)/$ http://%{SERVER_NAME}/$1/ [R,L]

The above is the code I am using to make sure the pages /login/ and /contact/ are SSL encrypted. I am not hardcoding URLs in my site so all relative urls reason redirecting a user, when they access http://www.example.com/login/ it will redirect them the https version. But once they are on that page ALL the links in the page get the https scheme. So want it when they are in https and click on a link that is NOT /contact/ or /login/ it will break them out of https by redirecting them to the http version. Right now it is not working and is causing infinite redirection. Anyone know how to do this?
« Last Edit: July 07, 2007, 03:43:17 PM by CrYpTiC_MauleR » Logged

[x] Fight | www.crypticmauler.com
"You must be
CrYpTiC_MauleR
Site Builder

Offline Offline

Posts: 489



WWW
« Reply #1 on: July 07, 2007, 04:24:48 PM »

I got it working =o)

Code:
RewriteCond %{SERVER_PORT} !^80$
RewriteCond %{REQUEST_URI} !^/(contact|login)/$
RewriteRule ^([a-z]+)/$ http://%{SERVER_NAME}/$1/ [R=301,L]

RewriteCond  %{SERVER_PORT} !^443$
RewriteRule ^(contact|login)/$ https://%{SERVER_NAME}/$1/ [R=301,L]
Logged

[x] Fight | www.crypticmauler.com
"You must be
GrandSchtroumpf
Mentor

Offline Offline

Posts: 410



« Reply #2 on: July 08, 2007, 04:03:05 AM »

Why not using the "HTTPS" variable instead of the port?

Code:
RewriteCond %{HTTPS} =on
...

RewriteCond %{HTTPS} !=on
...
Logged
Pages: [1]
« previous next »
    Jump to: