Apache – Redirect HTTP to HTTPS using .htaccess

There are 2 parts in order to make this configuration:

1. httpd.conf file for Apache needs to be modified. By default – the AllowOverride is set to None which means that placing a .htaccess file in the necessary directory will not take affect. Therefore, a Directory directive is to be added to the apache configuration which enables .htaccess to take effect. Here’s how the configuration would look like:


<Directory "/home/httpd/html/Your_Web_Directory">
    AllowOverride All
</Directory>

2. The second part is to add a .htaccess file to your web directory for which the HTTPS redirection rule is to be written. Add the following lines of code to your .htaccess file and place it under your web directory set in the apache configuration:

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s