Redirect all HTTP traffic to HTTPS

There are lots of “plugins” and “applications” being sold to people these days which perform this step but they are not necessary. All you need is a small configuration edit. This works for both Apache and Nginx.

Apache

Place this inside your virtual-host configuration

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Nginx

Here is a block of code that goes into your per-server configuration for Nginx

server {
        listen 80;
        server_name example.com;
        rewrite ^ https://$server_name$request_uri? permanent;
}

That’s it! If you have any questions please send us an E-mail and we’ll be happy to help you!

Tags: , ,

Comments are closed here.