Https continuing on to non https pages

I have a contact form on my site which uses https the forced https is working fine when navigating from a non-secure page such as the home page.

however when I navigate to regular http pages on my site from the form these pages now have https.

the weird thing is this has only started happening although nothing has changed in the .htaccess file.

I am using the following to force https:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^contact.html(.*) https://%{SERVER_NAME}/contact.html$1 [R]

I have scoured the net and there doesn’t seem to be anything out there explaining this problem, I have heard that using absolute urls to link to http pages will work but I would prefer not to use this.

To switch back you need a rule that does the exact opposite of your rule, i.e. a rule that says “If https is active and any other URL than contact.html is requested, redirect to the requested URL using http instead of https”.

Try this:

RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule !^contact.html http://%{SERVER_NAME}%{REQUEST_URI} [L,R]


PS. I’ve added the [L] flag to this rule to make it faster. Please also add it to your other rules.

Thanks! thats working now.

Weirdly enough I when I added your fix it was working for all of the html pages on the site but when I navigated to any pages with a .php extension it was keeping the https however I found out what was causing this.

I was creating new contact php forms in a test folder on the site and was trying to add SSL to them but for some reason the .htaccess method wasn’t working so I forced https on these pages using the following code:

if ($_SERVER['SERVER_PORT'] != 443) {
header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

somehow this seemed to affect other pages also, including any .php pages which were linked to from .html pages using SSL.