Redirecting Http to Https (SSL) Using Apache Htaccess Redirection Rules

Http to Https Redirection

SSL is a premium feature which all hosts provides specially upon request. For people who deals with Websites which are for Buy/Sell, or simply Ecommerce, SSL would be a required feature. SSL adds security to the browsing session since no data will be revealed and all things will be kept private which enhances the User and make him trusty enough to buy the product from the Mentioned Site. SSL costs some extra bucks but it sure increases the reliability, that a client makes on the site and thus resulting in more sales and henceforth.

So, A Lot of people buy SSL but are confused how to force the users to redirect to Https instead of the ordinary http which people come in. This can be done with a simple set of redirection urls, which amend or force up the user to https whenever he try to access http. So here Goes.

1.Find the htaccess file present in the site root.

2. Add these set of rewrite rules to it.

RewriteEngine On
RewriteCond %SERVER_PORT !443
RewriteRule (.*) [R]

3. Done!

For a Better redirection, which is not based on Port no. and works on, when accessed from all ports is here. This seems to be the most reliable redirection, since it forces all users,with no Port checking or anyother extra steps.

RewriteEngine On
RewriteCond %HTTPS off
RewriteRule (.*) https://%HTTP_HOST%REQUEST_URI

4 Responses to “Redirecting Http to Https (SSL) Using Apache Htaccess Redirection Rules”

  1. my eyes quite caught by this write ups,nice share, i learn something from this

  2. im also a wesbite owner, this kind of tricks is really helpful but if you wanna go for SSL because you have a buy and sell site, i rather go for webhosting that bundle an SSL package, anyways, this is a good security protection for small scale sites...not really recommended for securing information...thanks for sharing

  3. tejraj June 12, 2012

    Useful post.

  4. shoaibul99 April 19, 2016

    I have an own website.I need help like this

Leave a Reply