2016-09-15 195 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來進行測試。