I use a custom 404 page in a PHP application.
On that 404 page, I check for certain 'known' older pages that no longer exist, and then redirect user to newer or most relevant current page. Works great.
Now I am faced with a series of old images that have been removed, and am looking for a way to redirect the images to a new image (all inside of the php code if possible).
I have hunted around briefly and came up empty.
Any way to do this?
Here is a sample of my code:
<?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}\">";
}
//
// -------------------------------------------------------
?>