Forum Moderators: coopster

Message Too Old, No Replies

Custom 404 page

Trying to guess where people were going and forward them there

         

MatthewHSE

5:00 pm on May 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm using a custom 404 error page called (creatively) 404.php. I'm reorganizing some of my CMS categories on my site, and as such, this 404 file will probably see a lot of use in the near future.

The articles will all still be there, just at different URL's. So, my goal is to add some code to my 404.php file to analyze the request and attempt to forward users to the page they wanted to go to, at its new location.

The problem is I can't figure out how to get the requested URL in the first place. All the normal methods like PHP_SELF and QUERY_STRING naturally refer back to 404.php itself. (I tried it on a chance it might work.) I also tried to grab the referer, but that also doesn't work (and naturally wouldn't work for the SE's anyway).

So how can I get the actual requested URL so I can process it with PHP? I've been trawling through the PHP manual but can't find anything that really looks relevant.

Thanks in advance for any ideas,

Matthew

Receptional Andy

5:13 pm on May 23, 2008 (gmt 0)



The simple answer is
$_SERVER['REQUEST_URI']
.

It sounds like you may have a full url in your errordocument (which would trigger a redirect) so make sure you have /404.php rather than http://www.example.com/404.php.

Samizdata

5:33 pm on May 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The articles will all still be there, just at different URL's

Unless I am missing something here (always a possibility) then some carefully crafted Redirect/RedirectMatch directives in .htaccess (or Windows equivalent) should eliminate any possibility of a user seeing an error page - and will also preserve ranking in the search engines.