添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

0 人关注

我已经对我的WordPress网站的htaccess文件进行了修改,将流量从http重定向到https。

大多数情况下,它工作得很好,并将流量重定向到https,但有些情况下它没有。

例如,如果我试图访问地址为http的主页,它会重定向到https,但如果我试图访问网站上另一个网址为http的页面,它就会停留在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
    

    我已经尝试了其他问题中的许多答案,我还可以尝试什么?

    1 个评论
    我知道你正在尝试手动操作,但我建议你使用这个插件,它可以为你自动完成这项工作 wordpress.org/plugins/https-rediction
    php
    wordpress
    apache
    .htaccess
    redirect
    thewzrdharry
    thewzrdharry
    发布于 2017-10-18
    5 个回答
    usman ikram
    usman ikram
    发布于 2018-06-15
    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>
    
    使用这个代码,你仍然面临同样的问题?
    是的,同样的问题
    Brént Russęll
    Brént Russęll
    发布于 2018-06-15
    0 人赞同

    为什么你在底部有以下内容?当你删除这个时,会发生什么?我认为这可能与顶部的RewriteCond %{HTTPS}发生冲突。如果你删除这个,会发生什么?

    RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
    RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
    
    谢谢,我已经删除了那一行。它并没有解决我的https问题,但显然不需要它。
    Pawan Thakur
    Pawan Thakur
    发布于 2018-06-15
    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
    
    RedEyedMonster
    RedEyedMonster
    发布于 2018-06-15
    0 人赞同

    在设置中改变你的网站地址。

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

  • 重写引擎在
  • RewriteCond %{HTTP_HOST}^yoursite.com [NC,OR)
  • RewriteCond %{HTTP_HOST}^www.yoursite.com [NC]
  • RewriteRule ^(.*)$ https://www.yoursite.com/ $1 [L,R=301,NC]
  • 我的设置已经被改变了。这些行只是删除了www.吗?因为我目前的htaccess已经这样做了。
    Dominic Desbiens
    Dominic Desbiens
    发布于 2018-06-15
    0 人赞同

    我也遇到了同样的问题,解决的方法其实很简单......只要确保把https重定向放在Wordpress的原始重写代码之前就可以了......

    # 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