如果我使用地址进入我的域名:" www.domain.com"它有效,但如果我这样做" domain.com"它没有,我收到这条消息:
警告:无法修改标题信息 - 已在第1228行的/home/eventtou/public_html/wp-includes/pluggable.php中发送的标题(由/home/eventtou/public_html/index.php:2开始输出)< / p>
这里是index.php
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
以下是我的pluggable.php
的第1197-1232行function wp_redirect($location, $status = 302) {
global $is_IIS;
/**
* Filter the redirect location.
*
* @since 2.1.0
*
* @param string $location The path to redirect to.
* @param int $status Status code to use.
*/
$location = apply_filters( 'wp_redirect', $location, $status );
/**
* Filter the redirect status code.
*
* @since 2.3.0
*
* @param int $status Status code to use.
* @param string $location The path to redirect to.
*/
$status = apply_filters( 'wp_redirect_status', $status, $location );
if ( ! $location )
return false;
$location = wp_sanitize_redirect($location);
if ( !$is_IIS && PHP_SAPI != 'cgi-fcgi' )
status_header($status); // This causes problems on IIS and some FastCGI setups
header("Location: $location", true, $status);
return true;
}
endif;
我该怎么做才能解决这个问题?提前谢谢你!
答案 0 :(得分:0)
如果您运行apache,请将.htaccess文件放在网站的根目录中,或将下面的部分插入现有的.htaccess
<IfModule mod_rewrite.c>
##-- Initialize and enable rewrite engine
##-- Documentation http://httpd.apache.org/docs/misc/rewriteguide.html
RewriteEngine On
##-- set the following line like e.g.: RewriteBase /myfolder/
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
</IfModule>
然后对domain.tld的所有访问都被重定向到www.domain.tld
这并没有真正解决代码中的问题。但从SEO的角度来看,无论如何都要防止您重复内容,这是一个好主意。而且因为只访问了www,问题就不再重要了。