mod_rewrite ssl redirect

Posted by Thomas on Server Fault See other posts from Server Fault or by Thomas
Published on 2010-03-20T16:29:13Z Indexed on 2010/03/20 16:31 UTC
Read the original article Hit count: 218

Filed under:

Hi all,

I want to use mod_rewrite to ensure that certain pages are served with SSL and all others normally, but I am having trouble getting it to work

This works (redirect to SSL when request uri is for users or cart)

RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} users [OR]
RewriteCond %{REQUEST_URI} cart
RewriteRule ^(.*)$ https://secure.host.tld/$1 [R,L]

So, to accomodate for a user not to keep browsing the site with ssl, when requesting other uris, I thought the below, but doesn't work: (when port is 443 and request uri is not one of uris that need to be served by ssl, redirect back to normal host)

RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/users [OR]
RewriteCond %{REQUEST_URI} !group
RewriteRule ^/?(users|groups)(.*)$ http://host.tld/$1 [R,L]

Any help?

Thanks

© Server Fault or respective owner

Related posts about mod-rewrite