我在.htaccess
目录中有以下webroot
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(/admin/)
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
然后,在public
目录中,我有以下.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?$1 [QSA,L]
# Force HTTPS
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
然后,如果我点击以下网址:
浏览器被重定向到:
当通过HTTP加载站点(不强制)时,省略此部分。
答案 0 :(得分:2)
强制https
规则必须放在root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^$ public/ [L]
RewriteCond %{REQUEST_URI} !^(/admin/)
RewriteRule (.*) public/$1 [L]
</IfModule>
从http->https
删除public/.htaccess
规则并清除浏览器cahce以对其进行测试。