簡體   English   中英

htaccess將所有流量重定向到https

[英]htaccess Redirect All Traffic to https

在使用htaccess進行操作時,我是一個初學者,因此請耐心等待我的愚蠢問題。 我知道這個問題已經解決了很多(例如此處此處此處 ),但似乎不適用於我的情況。 我的瀏覽器在我的htaccess文件中顯示以下代碼的“重定向循環”錯誤:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Trying to redirect to https
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>

我知道在重定向到https之前,這可能與RewriteCondRewriteRule ,但是我真的不知道我在這里做什么,也不知道要更改什么。

更新:

一些可能有用的更多信息:

  1. 當我刪除“重定向到https”代碼並手動鍵入https://my.site.com它加載就好了。
  2. 另外,在我不小心刪除目錄中的.htaccess文件之前,重定向到https的效果很好。
  3. 我要重定向的應用程序駐留在另一個也有.htaccess文件的應用程序的子文件夾中。 這是該應用程序的代碼:

    <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] RewriteEngine On </IfModule>

這是螢火蟲說的: 第一張截圖第二截圖

更改規則的順序,並在其他內部重寫規則之前保留301條規則:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Trying to redirect to https
    RewriteCond %{HTTPS} off
    RewriteCond %{SERVER_PORT} !=443
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

暫無
暫無

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

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