.htaccess 如果所有请求都通过index.php路由,如何强制htaccess文件的HTTPS?

vq8itlhq  于 7个月前  发布在  PHP
关注(0)|答案(1)|浏览(66)

我有一个代码在我的htaccess文件中路由每一个请求,而不是一个文件或目录到index.php的代码如下:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [QSA,L]
</IfModule>

如何编辑此代码以强制所有请求也为https?
我试图搜索论坛,但找不到我当前问题的答案。

332nm8kg

332nm8kg1#

你有没有尝试在你的路由规则之前添加HTTPS强制规则,如果我没有弄错的话,它应该看起来像这样

<IfModule mod_rewrite.c>
RewriteEngine On

# HTTPS enforcement
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L] 
#if it didn't work with [L] try adding [L,R=301] instead

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [QSA,L]
</IfModule>

下面是stackoverFlow中的一个类似问题,在2012 check here中得到了回答

相关问题