簡體   English   中英

在htaccess中強制使用HTTPS,同時也僅使公用文件夾可訪問

[英]Force HTTPS in htaccess while also only making public folder accessible

這個.htaccess文件在我的/ public_html /文件夾中:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ public/ [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>

這個.htaccess在我的/ public_html / public /文件夾中

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

我需要添加如下規則:

RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

我遇到了重定向過多次的問題。

我仍然需要將公用文件夾用作我的根目錄,並仍使用/ public /中的前端控制器,但我想將所有流量定向到https。

有人可以幫我了解如何解決嗎?

我是否需要更改與/ public /文件夾有關的重寫規則?

/public_html/public/文件夾的.htaccess中添加http->https規則,如下所示:

<IfModule mod_rewrite.c>

  RewriteCond %{HTTPS} !=on
  RewriteRule (.*) https://%{HTTP_HOST}/$0 [R=301,NE,L]

  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

確保在新瀏覽器中進行測試或完全清除瀏覽器緩存。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM