为什么301重定向显示为200 OK?

时间:2016-05-17 04:24:30

标签: php apache .htaccess redirect mod-rewrite

我试图理解为什么我似乎无法将此重定向作为301重定向。

我之前编写了一个url缩短脚本,这是我似乎无法理解的最后一步..

这是我的.htaccess

RewriteRule ^shorten/(.*)$ shorten.php?longurl=$1 [L]
RewriteRule ^([A-Za-z0-9]+)$ redirect.php?url=$1 [L]

这是我的redirect.php页面

include 'databaseClass.php';
$urlShortner = new urlShortner($db);

if(!preg_match('/[A-Za-z0-9]+/', $_GET['url']))
{
    die('That is not a valid short url');
}

header('HTTP/1.1 301 Moved Permanently');
header('Location: ' .  $urlShortner->redirectUrl());
exit;

出于某种原因,它报告为200 OK而不是301 perm重定向..我已经尝试将重写设置为[R = 301],但如果我这样做,页面就会停止工作。

0 个答案:

没有答案