简体   繁体   English

WordPress多站点www非www页面重定向失败

[英]Wordpress Multisite www non-www Page Redirect Failure

My Wordpress Multisite is setup without the www. 我的Wordpress多站点设置没有www。 I was having an issue whenever I would add the www. 每当添加www时,我都会遇到问题。 ie www.domain.com/post-name/ would redirect me to domain.com. 即www.domain.com/post-name/会将我重定向到domain.com。

I soon found out that it was because I removed the /blog/ part of the permalink structure in the super admin section for the site. 我很快发现这是因为我在网站的超级管理员部分中删除了永久链接结构的/ blog /部分。 The redirects were working fine again. 重定向再次正常运行。

However the pages weren't. 但是页面不是。 So whenever I accessed www.domain.com/page1 it would redirect back to domain.com 因此,每当我访问www.domain.com/page1时,它将重定向回domain.com

Any solution to this? 有什么解决办法吗?

Remove the define('NOBLOGREDIRECT', 'http://www.domain.com'); 删除define('NOBLOGREDIRECT','http://www.domain.com'); from your wp-config file. 从您的wp-config文件中。

Add this in your htaccess file right under RewriteEngine On 将此添加到您的htaccess文件中,位于RewriteEngine On下

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

You don't need to add any codes in htaccess file. 您无需在htaccess文件中添加任何代码。 There is very easy solution to this. 有一个非常简单的解决方案。 In the 'Network Admin -> Settings -> Domains' page, add both the www. 在“网络管理->设置->域”页面中,添加两个www。 and non-www. 和非www。 versions of the domain, select the box of 'primary' for if you want to mainly use for www. 域的版本,如果要主要用于www,请选中“主要”框。 or non-www. 或非www。 and both will be assigned to the website. 并将两者都分配到该网站。

尝试将以下内容添加到您的wp-config.php中

define( 'NOBLOGREDIRECT', 'http://domain.com' );

I don't have enough reputation points so I'm posting this as an answer instead of a comment to where I got the solution from. 我的信誉点不足,因此我将其发布为答案,而不是评论我从哪里获得解决方案。

I added the following code into wp-config.php and while it wasn't used for its intended use, it still worked to solve my 'WP Multisite non-www redirect to www' issue. 我将以下代码添加到wp-config.php中,尽管未将其用于预期用途,但仍可以解决“ WP Multisite non-www redirect-www”问题。

define( 'NOBLOGREDIRECT', ' http://example.com ' ); define('NOBLOGREDIRECT',' http://example.com ');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM