【发布时间】:2014-10-26 19:55:56
【问题描述】:
我正在尝试使用 php 301 重定向而不是 htaccess 来移动多个动态 URL。
我不知道如何把它放在一起,虽然我有点超出我的深度,到目前为止都是这样。
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.new-website/new-folder/ $url="http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$url=str_replace('http://www.website.com/old-folder/','',$url);
echo $url; ");
?>
旧网址:http://www.website.com/old-folder/news-article/full.php?=任何东西
新网址:http://www.new-website.com/new-folder/news-article/full.php?=任何东西
我想将当前 URL 的第二个 / 之后的任何内容插入标题位置
/old-folder/ 之后的任何内容每次都会有所不同。
简单来说,我正在尝试这样做:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.new-website/new-folder/ *insert end of URL from current address bar here* ");
?>
【问题讨论】:
-
使用
header("Status: 301 Moved Permanently")。 -
您应该考虑使用 .htaccess 来执行此操作,因为您的选项可能会导致 HTTP 标头拆分。
-
使用 .htaccess 或 vhost conf 文件来定义你的重写,因为它在服务器上会轻很多。 (虽然我猜你不了解 rewrite 模块,这就是为什么你打算在 php 中这样做?)
标签: php redirect http-status-code-301