Force Redirect HTTP to HTTPS in Apache – Many of sites required to always running with SSL only. And we need to ensure that every user must access the website through SSL. If any user tried to access the 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.

Advertisement

Option 1 – Redirect HTTP to HTTPS

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 – Redirect HTTP to HTTPS

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} [R,L]

If you want to redirect specific URL to https. Use following settings. For example, if anyone tried to access the always-secure.html file on the 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]
Share.

Leave A Reply