William
William

Reputation: 1033

Htaccess HTTPS redirection

I'm trying to get my .htaccess file to redirect only certain pages/folders to https and if its not the pages that need to be encrypted then it should shoot the user the the http page. Also I would like to be able to list certain folders that can either be HTTP or HTTPS

Here is what I tried using writing up myself. But seemed to not work all correctly.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteCond $1 ^(myaccount|payment\.html)
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} 443
RewriteCond $1 !^(myaccount|payment\.html)
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>

Upvotes: 1

Views: 714

Answers (2)

Brian
Brian

Reputation: 13517

This should do what you want.

RewriteCond %{SERVER_PORT} 443 [NC]
RewriteCond %{REQUEST_URI} !^/(myaccount|payment)\.html [NC]
RewriteRule . http://www.domain.com/%{REQUEST_URI}/ [R=301,L]

Upvotes: 0

Marc B
Marc B

Reputation: 360872

You're checking a literal $1 in your RewriteCond patterns. It should be:

RewriteCond %{REQUEST_URI} ...stuff to match against here...

Upvotes: 1

Related Questions