1

a normal http to https rewrite could look like this:

RewriteEngine On
# RewriteCond %{HTTP_HOST} !^example.com$
# RewriteRule /.* https://example.com/ [R]

but this code specifies the site to "example.com"

Is there anyway to make a "global" rewrite, so regardless if anybody opens example.com, broken.example.com or even example.Lom, (as long as the DNS is pointing to the server) so will it simply put a https on it?

for servers that have more than one domain name.

Would be great to be able to use the same code everywhere..

1 Answers1

0

You can use the following code in any virtual host to redirect http to https:

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

You can set it globally by setting the code in your default virtualhost (/etc/apache2/sites-available/000-default.conf on debian) to redirect any http request on any domain to its https version:

<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    ...
</VirtualHost>
Chris
  • 232
  • 2
  • 8