2016-03-02 72 views
0

如果我在我的域名上輸入了「www.domain.com」,它可以正常工作,但是如果我像「domain.com」那樣執行操作,則不會顯示此消息:我的域名無效

警告:不能更改頭信息 - 頭已經發出在/home/eventtou/public_html/wp-includes/pluggable.php(輸出開始/home/eventtou/public_html/index.php:2)上線1228

這裏的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'); 

,這裏是線1197 - 我pluggable.php 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

嘗試使用頁面頂部的ob_start()一次 – Deep

+7

可能的重複[如何解決Headers已經發送PHP錯誤](http://stackoverflow.com/questions/8028957/how-to-fix- headers-already-sent-error-in-php) –

+0

如果您的主機配置爲回答'domain.com'請求,請與您的ISP聯繫。這是一種子域,在您簽約主機服務時不會自動配置。如果主機歸您所有,我認爲這對於httpd.conf文件很重要。 – statosdotcom

回答

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被訪問,所以問題不再重要。