Rewrite .htaccess for https

倾然丶 夕夏残阳落幕 提交于 2020-01-17 18:18:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!