Forum Moderators: phranque
I read that a "fix" to the problem that some search engines have with a dynamic page could be solved with a 404 error redirect. For example, instead of somepage.php?category=cars&name=mustang you could link to a nonexistant page of /cars/mustang/somepage.php. When the server doesn't find that page, it redirects to the page set in .htaccess, and you can explode the referring URL.
The tutorials I read said to use
$url = explode("/",$REQUEST_URI);
$url = explode("/",$_SERVER['HTTP_REFERER']);
Is this because of a variable set in httpd.conf. Or do the server variables for my browser get reset when apache redirects through .htaccess, or maybe something else?
Thanks
Welcome to WebmasterWorld [webmasterworld.com]!
You could try REQUEST_FILENAME to get the filename without query string, etc.
I would strongly advise against using this "404 redirect" method for two reasons. First, the server will return a 404-Not Found response to the requesting user-agent, which will confuse some search engine spiders. Secondly, even if it does not confuse them, it still requires a "handshake" with the user-agent. That is, the user-agent must receive the 404 response, and then re-request the resource from the URL given in the 404 response message-body.
A good policy is to never push your luck by returning inappropriate response codes, and to never do any external redirect when an internal rewrite will do. The first leads to unexpected/unwelcome results, and the second is horribly inefficient.
You will be a lot happier with the results if you simply use mod_rewrite to internally rewrite these requests to your script.
HTH,
Jim