Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Linux/Force Rewrite To HTTPS Except For Page

October 31, 2018

Force Rewrite To HTTPS Except For Page

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

Have content delivered to your mail. Subscribe below.

About Me

I'm Ulysses, Cloud Engineer at Cardinal Health based in Columbus. This blog is about Linux and Cloud technology. When off the grid, I enjoy riding my electric skateboard. I've surfed, snowboarded and played the saxophone in the past. I hope you find this website helpful. It's powered by WordPress and hosted on AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021