.htaccess 如何使强制MVC(PHP)和强制HTTPS与htaccess?[副本]

wwtsj6pe  于 2023-05-01  发布在  PHP
关注(0)|答案(2)|浏览(129)

此问题已在此处有答案

.htaccess redirect http to https(14个答案)
昨天关门了。
这篇帖子昨天编辑并提交审核,未能重新打开帖子:
原始关闭原因未解决
这是PHP MVC程序的htaccess代码

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php?url=$1 [L]

!请正确阅读!

我想要的是:

*强制https
*然后转到索引。php文件并发送url数据
!请正确阅读!

我添加了新的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
请回答这个问题

正确阅读

对不起我的英语不好

drnojrws

drnojrws1#

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
vohkndzv

vohkndzv2#

谢谢大家,我找到了答案,我不认为这是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]
  • 强制HTTPS ✓
  • 转到索引,并发送url数据✓

有关RewriteEngine的信息源为Here
这很奇怪,我回答了自己的问题。
如果我的解释很难理解,我很抱歉:)

相关问题