• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

force https

Force Rewrite To HTTPS Except For Page

October 31, 2018

Here’s how to force a rewrite pages to https except for a couple of pages.

RewriteEngine On
 
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_URI} !^\/page1\/
RewriteCond %{REQUEST_URI} !^\/page2\/
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]    
 
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} \/page1\/ [OR]
RewriteCond %{REQUEST_URI} \/page2\/
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]

RewriteEngine On RewriteCond %{HTTPS} =off RewriteCond %{REQUEST_URI} !^\/page1\/ RewriteCond %{REQUEST_URI} !^\/page2\/ RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301] RewriteCond %{HTTPS} =on RewriteCond %{REQUEST_URI} \/page1\/ [OR] RewriteCond %{REQUEST_URI} \/page2\/ RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]

The first rule-set will redirect all pages not /page1/ or /page2/ to the same URL but https://.
The second rule will make sure that /page1/ and /page2/ are redirected back to http:// if accessed via https://.

Here’s the Stackdriver source.

Filed Under: Linux Tagged With: force https, http

  • Home
  • About
  • Archives

Copyright © 2023