【发布时间】: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,请仔细阅读问题。