Redirect your website from http://www.example.com to https://www.example.com using htaccess file in your Apache web server. It is crucial to collect financial and confidential information from a person through HTTP over SSL to make sure the transactions are secure. A customer cannot be asked to type https in front of the URL each your website is visited. So you can make sure they are automatically redirected to the HTTPS version of the website each time they visit the URL.
Redirect http to https using htaccess
Before going ahead make sure you have SSL properly configured in your server with the necessary certificates in their place. Type https://www.example.com and make sure your website loads. Then ensure your Apache web server supports mod rewrite. Now create a file named .htaccess inside the document root (www or htdocs or public_html folder) if it already exists just edit it. Add the following lines inside the .htaccess file. Replace example.com with your domain name
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
What actually happens here is the rewrite engine checks at which port the request was made by the visitor, if it was made on port 80 (the default port for Web Servers) it is redirected to https://www.example.com/ The $1 at the end of the URL is used for a wild card redirect i.e. all files and folders accessed under example.com/ will be redirected to the https page. The 301 is the web server response code which says the page has been “Moved Permanently” to another location.
Note:- Make sure you enter the URL as it was signed by the certificate authority. If you bought an SSL certificate for example.com you cannot use it for www.example.com and vice versa. If you do use it the web browser will display an error.
Leave a Reply