Apache Redirect HTTP to HTTPS

Force Redirect HTTP to HTTPS in Apache – Many of sites required to always running with ssl only. And we need to ensure that every use must access website through ssl. If any user tried to access website with non-ssl url, He must be a redirect to ssl website. This tutorial will help you to redirect website to ssl url each time using Apache mod_rewrite module.

Option 1:

Edit website VirtualHost in Apache configuration file and add the following options. Change www.example.com with your actual domain name.
Redirect permanent / https://www.example.com/ 

Option 2:

Edit website VirtualHost in Apache configuration file and add the following settings. You may also add the same settings in .htaccess file under document root of your website.
  RewriteEngine On   RewriteCond %{HTTPS} off   RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
If you want to redirect specific url to https. Use following settings. For example if anyone tried to access always-secure.html file in website. The user must have to access url with ssl.
RewriteEngine On RewriteRule ^always-secure.html$ https://www.example.com/always-secure.html [R=301,L] 

Thanks for Visit Here

Comments