2016-09-15 98 views
1

追加 “公共” 我有以下.htaccesswebroot目录:强制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://example.com/

的浏览器被重定向到:

https://example.com/public/

当站点被加载通过HTTP(而不强制)中,省略这一部分。

回答

2

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来进行测试。