【问题标题】:WordPress 301 redirect for all pagesWordPress 301 重定向所有页面
【发布时间】:2020-04-30 06:45:24
【问题描述】:

我有一个 WordPress 网站,我希望强制所有页面转到 https 和非 www

所以我想要跟随重定向。

http://example.com --> https://example.com
www.example.com --> https://example.com
http://example.com/abcd --> https://example.com/abcd
www.example.com/abcd --> https://example.com/abcd

我的 .htaccess 文件中有以下代码

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

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


问题是它只正确重定向主页,对于内页我得到一个页面未找到/站点无法访问错误。

【问题讨论】:

  • 一个简单的谷歌给出了这个:freecodecamp.org/news/…
  • 我用谷歌搜索了这个问题并访问了许多页面。如果我在谷歌搜索或之前提出的问题中找到答案,我就不会在这里发布问题。您提供链接的文章未说明如何将所有 www 流量重定向到非 www,请仔细阅读问题。

标签: wordpress apache


【解决方案1】:

试试这个:

RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]

【讨论】:

  • 谢谢,这很好。试过这个,它仍然不适用于内页。它不适用于http到https。它仅适用于 wwwnon-www
猜你喜欢
  • 1970-01-01
  • 2012-12-21
  • 1970-01-01
  • 2012-10-09
  • 2016-03-25
  • 1970-01-01
  • 2020-03-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多