mardi 4 août 2015

Does redirecting www to https:// require AllowOverride or can it be set globally?

I am trying to change my apache2 server configuration which I'm sure is sub-optimal. Right now I have all the AllowOverride set to None. I would like to keep that configuration to set global rules and increase page load times.

However, the problem now is that I use a separate virtual host and directory with a .php file to redirect www.example.com to https://www.example.com. I'm sure that this is not optimal. I would prefer to use a mod_overwrite.

From what I have read, a rule set like the following would enable this. However, I would like to know where to put this code if I want to keep AllowOverride None.

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I believe that if I add a rule set like this in the right place, I can also disable the additional virtual host that I'm using to redirect.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire