Apache https redirect

From snippet wiki
Jump to navigation Jump to search

To redirect all users from the unsecure port 80 to the secured https connection use these lines within the virtual host definition:

<VirtualHost *:80>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>

And within the virtual host definition of the ssl connection add this line for showing Strict-Transport-Security:

<VirtualHost *:443>
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
</VirtualHost>