强制HTTP到HTTPS URL中
问题描述:
追加 “公共” 我有以下.htaccess
内webroot
目录:强制HTTP到HTTPS URL中
<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>
然后,如果我击中以下URL:
的浏览器被重定向到:
当站点被加载通过HTTP(而不强制)中,省略这一部分。
答
力https
规则必须放在根目录的.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>
从public/.htaccess
删除http->https
规则和清晰的浏览器cahce来进行测试。