301使用php代码重定向问题

时间:2014-05-08 18:59:10

标签: php redirect

我有这个为页面重定向编写的代码,并为正确的SEO生成301

  if(preg_match("/[index.php]$/", $_SERVER[REQUEST_URI])) {

     $url = "http://" . $_SERVER[HTTP_HOST] . preg_replace("/(index.php)$/", "", $_SERVER[REQUEST_URI]);
     $sapi = php_sapi_name();
     if(PHP_VERSION >= '4.3.0') {
        header("Location: $url", 0, 301);
     }
     else if($sapi == 'cgi' OR $sapi == 'cgi-fcgi') {
        header("Location: $url");

        header('Status: 301 Moved Permanently');
     }
     else {
        header("Location: $url");
        header('HTTP/1.1 301 Moved Permanently');
     }
  }



http://www.dsmla.com returns a 200 (OK) response. 
http://dsmla.com returns a 200 (OK) response.
http://www.dsmla.com/index.php returns a 301 (permanent) redirect
http://dsmla.com/index.php returns a 301 (permanent) redirect

我的代码适用于2个网址但我希望它只能显示200个仅1个链接

0 个答案:

没有答案