Rewrite .htaccess for https

2019-09-23 04:58发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-23 05:19

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]
查看更多
登录 后发表回答