我的脚本有一个奇怪的错误,如果 URL 以“/”结尾,则我只想将用户重定向到最后没有任何“/”的相同 URL。
我收到此错误:
Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/xxx/httpdocs/series.php:1) in /home/httpd/vhosts/xxx/httpdocs/series.php on line 7
Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/mxxx/httpdocs/series.php:1) in /home/httpd/vhosts/xxx/httpdocs/series.php on line 8
代码:
<?php
$urlLast = $_SERVER['REQUEST_URI'];
$urlLast = substr($urlLast, -1);
if (($urlLast == '/') && (!strstr($_SERVER['REQUEST_URI'], 'en-streaming')))
{
$newURL = substr($_SERVER['REQUEST_URI'],0,-1).'-en-streaming';
header("Status: 301 Moved Permanently", false, 301);
header("Location: ".$newURL."");
}