HTTP/HTTPS redirects for certain URIs

New to mod_rewrite? This is a good place to start.

HTTP/HTTPS redirects for certain URIs

Postby wrathican » Wed Jul 28, 2010 11:13 pm

Hi All,

I've been having an issue for a little while with redirecting only certain URIs to HTTPS and the rest to HTTP.

What I want is the follow:
- The site to use HTTP for all pages unless explicitly told to use HTTPS
- Redirect these special pages to use HTTPS
- When in HTTPS, and you choose a non SSL page, to be redirected to HTTP.

The Problem:
Currently with the rules that I have (Found below) I can redirect from HTTPS to HTTP for all URIs except those explicitly defined. When redirecting to HTTPS for those defined URIs from HTTP the site seems to get stuck in a redirect loop.

The rewrites I am using are as follow:
Code: Select all
# Force HTTP for non special pages.
RewriteCond %{SERVER_PORT} !^80$
RewriteCond %{REQUEST_URI} !^/special1(.*)$ [OR]
RewriteCond %{REQUEST_URI} !^/special2(.*)$ 
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

# Force HTTPS for special pages
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_URI} ^/special1(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/special2(.*)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]


Thanks in advance,
Ash
wrathican
 
Posts: 5
Joined: Tue Nov 18, 2008 1:42 pm

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 6 guests

cron