【发布时间】:2021-02-12 01:40:17
【问题描述】:
我想在我的网站上强制使用 https,但它与我的 .htaccess 的当前规则兼容
这是我目前的 htaccess 文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
谢谢
【问题讨论】:
标签: .htaccess mod-rewrite https
我想在我的网站上强制使用 https,但它与我的 .htaccess 的当前规则兼容
这是我目前的 htaccess 文件:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
谢谢
【问题讨论】:
标签: .htaccess mod-rewrite https
您能否尝试以下,如果变量%{HTTPS} 是否打开,您需要在其中查找条件,将此条件添加到已经存在的条件。另外请不要将它与现有的 URL 混合,因为它可能会暴露给客户端/浏览器(以您显示的当前示例为例)。
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
【讨论】:
RewriteCond %{HTTPS} off 尝试:RewriteCond %{HTTPS} !on。还要告诉你的 Apache 版本?