Latest Post

Error: No input file specified.

While trying to run a codeigniter app the other day I came across this error just after I had finished uploading the files and making the ne...

Wednesday, November 30, 2011

Force SSL/https using .htaccess and mod_rewrite

I recently had to update a client's website to force the use of https on their site initially they wanted it for just a subsection of the website and then later on they decided they wanted it for the whole site. Fortunately i found this useful htaccess/mod_rewrite tip off the web fairly quickly.

1. For a subsection of the website (assuming this is in its own folder) use the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]


be sure to place the htaccess file inside the respective subfolder

2. For the whole website, use the following:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]


make sure to place the htaccess file in the website's root folder

Hope this helps someone as it did me. :)

Till next time, happy coding.

1 comment:

Chitika Ads