How To (HTTPS) Redirect Signup and Admin Pages Using .htaccess
“Simple is better than complicated and complicated is better than complex”. I’ve read that quote somewhere in blogosphere and abruptly occupies in my brain. Keeping every logic simple within the code is essential and beneficial not only for a team collaboration setup but also for yourself as a coder. KISS principle could explain it.
I find it pretty simpler and better doing the https/ssl redirect using .htaccess than coding it under your favorite server-side script like PHP, particularly if the application code base is large and has an unorganized lines of code.
With a bit googling skill, below is the formulated code snippet.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} signup\.php
RewriteCond %{REQUEST_URI} admin
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.domain.com/$1 [R=302]
# Redirect non-secured pages to http
RewriteCond %{REQUEST_URI} !signup\.php
RewriteCond %{REQUEST_URI} !admin
RewriteCond %{REQUEST_URI} !\.(gif|jpg|swf|flv|png|js|css) # Consider checking web assets as it should as well redirect back to http
RewriteCond %{HTTPS} on
RewriteRule (.*) http://www.domain.com/$1 [R=302]
Simple right eh?

