簡體   English   中英

WordPress http 到 https 重定向

[英]Wordpress http to https redirection

我有一個實現了 ssl 的 wordpress 網站。 該網站在https://domain.com上正常運行。 我想將所有流量從http://domain.com重定向到https://domain.com 我用谷歌搜索了這個並將我的 .htaccess 更改為以下內容:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

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

重定向不起作用。 我嘗試過 Easy HTTPS 重定向、Wordpress HTTPS 等插件,但仍然無法正常工作。 有人可以幫我解決這個問題嗎? 我還想補充一點,當我嘗試訪問http://domain.com時,它無法連接。 提前致謝。

確保已更改wp_options表,siteurl和home中的設置以包括

option_name                     option_value     
siteurl                         https://<your domain>
home                            https://<your domain>

要一切從流量重定向HTTP://.comHTTPS://.com我使用這個插件(作品總是對我來說): https://wordpress.org/plugins/wp-force-ssl/

您不需要插件即可執行此操作...

嘗試在.htaccess的RewriteRule中進行以下更改:

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

嘗試將RewriteBase移到http重定向下方並移到wordpress部分。 它為我解決了我的問題。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

確保在 wp-config.php 中定義了 WP_SITEURL 和 WP_HOME

define('WP_HOME','https://yourdomain.com');
define('WP_SITEURL','https://yourdomain.com');

並添加此條件以檢查 https 是否位於 wp-config.php

 if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
    $_SERVER['HTTPS'] = 'on';
}

暫無
暫無

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

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