Will this work? Is there a better way?
It tested ok in IIS, I have yet to try on my apache servers.
Problem:
Needed a custom 404 page with intelligent redirect based upon the referrer. Easy with Apache, not as easy with IIS.
Solution???:
PHP Code:
<?php // ### Set $eREF to the Referring Page using QUERY_STRING (IIS) or REDIRECT_URL (apache) $eREF = !isset($_SERVER['REDIRECT_URL']) ? !isset($_SERVER['QUERY_STRING']) ? NULL : substr($_SERVER['QUERY_STRING'],4) : $_SERVER['REDIRECT_URL'] ;
// ### Redirect Based on the Referring Page switch ($eREF) { case "http://host/badpage1.php": header( "HTTP/1.1 301 Moved Permanently" ); header("location: http://host/goodpage1.php"); exit; case "http://host/badpage2.php": header( "HTTP/1.1 301 Moved Permanently" ); header("location: http://host/goodpage2.php"); exit; } ?>
I should also be able to do something like:
PHP Code:
<?php // ### Redirect Based on Regexp $pattern = '/^([a-zA-Z0-9]*)$/i' if (preg_match_all($pattern, $eREF, $match) === 0) { header( "HTTP/1.1 301 Moved Permanently" ); header("location: http://host/lookingfornumbers.php"); exit; } ?>
Last edited by Envision_frodo; 09-11-2009 at 04:54 PM..
Reason: Changed CODE to PHP for better highlighting
|