【发布时间】:2009-04-14 17:20:50
【问题描述】:
我在 PHP 应用程序中使用自定义 404 页面。
在那个 404 页面上,我检查某些不再存在的“已知”旧页面,然后将用户重定向到更新或最相关的当前页面。效果很好。
现在我面临着一系列已被删除的旧图像,并且我正在寻找一种将图像重定向到新图像的方法(如果可能,所有这些都在 php 代码中)。
我已经四处打猎了,结果空空如也。
有什么办法吗?
这是我的代码示例:
<?php
//-- grab info regarding bad request --
$root = $_SERVER['DOCUMENT_ROOT'];
$page = parse_url($_SERVER['REQUEST_URI']);
$page = $page['path'];
$referer = $_SERVER['HTTP_REFERER'];
$host = $_SERVER['REMOTE_HOST'];
//-- try to redirect old pages/files ----------------------
//
$page = urlencode($page);
if ( stristr($page, "some_old_file.zip") ) {
// Example file redirect
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=http://www.site.com/the/new/file.zip\">";
} elseif ( stristr($page, "some_old_page.php") ) {
// example webpage redirect
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=http://www.site.com/the/new/page.php\">";
} elseif ( stristr($page, "some_old_image.jpg") ) {
// not sure how to do this ...
// ...
// ...
// ...
// ...
// ...
// not sure how to do this ...
} else {
// everything else - direct to custom 404 search page
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;URL=http://www.site/com/the/custom/404_help.php?page={$page}\">";
}
//
// -------------------------------------------------------
?>
【问题讨论】: