在站点 URL 中安装了带有 www 的 Wordpress 网络。我该如何解决?

Installed Wordpress Network with www in the Site URL. How do I fix this?

我犯了一个大错。我建立了一个网络,但没有将站点名称更改为非 www,所以现在 example.com(没有 www)是一个不存在的页面。我该如何解决?

的变化

我试过 htaccess 重定向,但 wordpress 看到第一个请求,仍然说缺少 www。

我们无法编辑 Wordpress 源代码以进行重定向,因为它将在未来的更新中被破坏。我们不能将所有请求转发到该请求的 www 版本,因为这会破坏所有子域。

我通过对根 .htaccess 文件进行一些编辑解决了这个问题。

# This is probably how your file starts already
RewriteEngine On
RewriteBase /

# Then you add a condition: if the host starts with example.com
RewriteCond %{HTTP_HOST} ^example.com.*$
# And add a rule: redirect that url to the same url just with prepended with www
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/ [R=301,L]

# Here the file continues with other stuff from WP
RewriteRule ^index\.php$ - [L]