Page 1 of 1

Redirection to error 404 page

Posted: Mon Jul 14, 2008 9:42 am
by danaketh
Hi,

I have simple problem. I want users to be redirected to Error 404 page if they request non existing page (not a file). For example: user wants to get biography of his favourite actor, and because he does not want to click through the site, he simply write http://www.example.com/?actor=my-actor&page=biography into address line. That's ok. But when he makes a mistake and write http://www.example.com/?actor=my-actor&page=biogrpahy or so, I want him to be redirected to Error 404 page.

It's really not a problem for user, because header are not important for him but I want the same for robots. So it have to be correct way - robot must know that he crossed non existing page and get proper code.

Suddenly, I don't know how to solve it :( Maybe it's just because I'm really tired today ;)

Thanks for help...

Re: Redirection to error 404 page

Posted: Mon Jul 14, 2008 10:13 am
by Jaxolotl
you may use .htaccess file to redirect them

ErrorDocument 404 http://www.my_site.com/my_404_error_page.php
ErrorDocument 403 http://www.my_site.com/my_403_error_page.php
ErrorDocument 500 http://www.my_site.com/my_500_error_page.php

Re: Redirection to error 404 page

Posted: Mon Jul 14, 2008 1:22 pm
by WebbieDave
Your example implies that all requests are accessing /index.php?actor=my-actor&page=biography
This way, the web server will never actually send a 404. In this case, you can manually send the 404 through PHP if the lookup returns no results with the header function:

Code: Select all

header('HTTP/1.x 404 Not Found');

Re: Redirection to error 404 page

Posted: Tue Jul 15, 2008 3:53 am
by danaketh
WebbieDave wrote:Your example implies that all requests are accessing /index.php?actor=my-actor&page=biography
This way, the web server will never actually send a 404. In this case, you can manually send the 404 through PHP if the lookup returns no results with the header function:

Code: Select all

header('HTTP/1.x 404 Not Found');
Thanks. That's the solution I also figured out after few minutes after I created this topic :) I think that trying to redirect was a bad idea and this is actually the right way. Good to know that I'm going right way :)

Thanks guys!