这是PHP MVC
的htaccess代码
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L]
我想要的是:
我像这样添加了新的 htaccess 文件
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:CF-Visitor} !{"scheme":"https"}
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
在父目录中
但是,它仍然没有强制 HTTPS
请回答
对不起我的英语不好
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
谢谢大家, 我找到了答案,我认为这不是 100% 准确。 所以如果我错了请纠正我:)
只需在 .htaccess 文件上执行此操作
#Turn On RewriteEngine
RewriteEngine On
#If the HTTPS is off
RewriteCond %{HTTPS} off
#Redirect to HTTPS
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#%{HTTP_HOST} is equal to the host domain
#if the request url is a file ignore it
RewriteCond %{REQUEST_FILENAME} !-d
#if the request url is a dir, ignore it
RewriteCond %{REQUEST_FILENAME} !-f
#whatever was typed from start to end, move to index.php and send whatever the user has typed. and dont apply any RewriteRule after this
RewriteRule ^(.*)$ index.php?url=$1 [END]
有关 RewriteEngine 的信息来源是Here
这很奇怪,我回答我自己的问题。
如果我的解释难以理解,我很抱歉:)