· Apache Nginx

Redirect to HTTPS on Apache and Nginx

Instead of using rewrite rules to do this, lets use a 301 redirect, this could improve performance too as the server wont need process rewrites.

For Nginx, the below server block will redirect HTTP to HTTPS, set the server_name and the redirect will send the traffic to the HTTPS version.

server {
     listen 80;
     server_name aaron.mehar.me;
     return      301 https://$server_name$request_uri;
}

Apache is just as simple, using the same principle.

<VirtualHost *:80>
    ServerName aaron.mehar.me
    Redirect 301 / https://mydomain.com
</VirtualHost>

Dont forget to test the config with nginx -t or apachectl -S and then restart.

  • LinkedIn
  • Tumblr
  • Reddit