问题
I have an .htaccess file on my http site. Our system administrator made https settings and I can get my site by https. But the problem is that I can't rewrite .htaccess file. For example:
RewriteEngine On
Options -MultiViews
RewriteRule ^(index|getReadings|admin|adminNewDesign)\/([A-Za-z]*)$ $1.php?id=$2 [L,QSA,NC]
This works fine on http, but doesn't work on https. I tried like this:
RewriteEngine On
Options -MultiViews
RewriteCond %{HTTPS} On
RewriteRule ^(index|getReadings|admin|adminNewDesign)\/([A-Za-z]*)$ https://%{HTTP_HOST}/$1.php?id=$2 [L,QSA,NC]
And it doesn't work also. How to do it properly?
回答1:
You're currently redirecting only when the HTTPS
flag is ON
, which is obviously, not what you want.
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteRule ^(index|getReadings|admin|adminNewDesign)/([a-z]*)$ https://%{HTTP_HOST}/$1.php?id=$2 [L,QSA,NC]
来源:https://stackoverflow.com/questions/35747480/rewrite-htaccess-for-https