Force https on apache

Force https on apache or redirect http traffic to https site. Here’s a simple configuration that can be done within the .htaccess file on the site directory (do this in the site’s root directory if https is to be enforced for the entire site).

<IfModule mod_rewrite.c>
  RewriteEngine on
  Redirect permanent / https://%{HTTP_HOST}%/
  RewriteRule %{HTTPS} !=on
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>

Alternatively, you can modify the site configuration under /etc/apache2/sites-available/non-https-site

Advertisements

One thought on “Force https on apache

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