当手动输入以http开头的URL时,Wordpress网站htaccess不会重定向到https

时间:2017-10-18 11:04:54

标签: php wordpress apache .htaccess redirect

我在我的WordPress网站上更改了我的htaccess文件,将流量从http重定向到https。

大多数情况下它运行正常并将流量重定向到https,但有些情况下却没有。

例如,如果我尝试访问带有http in地址的主页,它会重定向到https,但是如果我尝试访问网站上的另一个页面,其中http为URL,则会保留在http:

  • http://example.com将重定向重定向到https://example.com
  • http://example.com/page保留在http://example.com/page

当前的htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On

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

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

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
</IfModule>
# END WordPress

我在其他问题上尝试了很多答案,我还能尝试什么?

5 个答案:

答案 0 :(得分:0)

试试这个

<IfModule mod_rewrite.c>

RewriteEngine On

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

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

答案 1 :(得分:0)

为什么底部有以下内容?删除它会发生什么?我认为这可能与顶部的RewriteCond%{HTTPS}冲突。删除此内容后会发生什么......

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

答案 2 :(得分:0)

适用于www和https

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

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

</IfModule>
# END WordPress

答案 3 :(得分:0)

在“设置”中更改您的网站地址: enter image description here

并在WordPress的.htaccess文件顶部添加以下代码。

  1. RewriteEngine on
  2. RewriteCond%{HTTP_HOST} ^ yoursite.com [NC,OR]
  3. RewriteCond%{HTTP_HOST} ^ www.yoursite.com [NC]
  4. RewriteRule ^(。*)$ https://www.yoursite.com/ $ 1 [L,R = 301,NC]

答案 4 :(得分:0)

我遇到了同样的问题,而且修复非常简单...请确保在Wordpress的原始重写代码之前放置https重定向...

例如:

&#13;
&#13;
# Redirection code (redirect no www to www and http to https)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
&#13;
&#13;
&#13;

相关问题