簡體   English   中英

使用 .htaccess 從 http 重定向到 https

[英]Redirect from http to https using .htaccess

我想將我的 wordpress 網站從 http 重定向到 https,所以我在.htaccess使用以下代碼。 但它給了我錯誤“頁面沒有正確重定向”。

RewriteCond %{HTTPS} off
RewriteRule ^ https://www.mywebsite.com%{REQUEST_URI} [L,NE,R=301]

我已經在wp-config文件中啟用了 SSL,如果我從一個頁面轉到另一個頁面,它工作正常。 只有當我在瀏覽器中復制粘貼任何http鏈接時才會出現問題,然后它不會重定向到https

我使用以下內容,還請確保您沒有可能啟用的緩存插件。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

接下來需要注意的是,確認WordPress地址和站點地址中有https 接下來,如果頁面中也只有http ,則有時還會顯示錯誤,因此請確認每個http已更新為https

將Http重定向到https:

  # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

暫無
暫無

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

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