Forum Moderators: coopster

Message Too Old, No Replies

How to redirect to 404.html using Header()

And tell google this is a 404 header?

         

iProgram

10:03 am on Mar 18, 2005 (gmt 0)

10+ Year Member



As you may already know, google has some problem with 302 header... In some case, we need to redirect to a custom 404 page in PHP source code.

For example, a page URL is htt p://www.site.com/info.php?id=123

When the DB query for id=123 returns nothing, I will redirect user to a custom 404 page, by using the following method:

header("Location: /404.html");

However, according to Server Header Check [webmasterworld.com], I just sent a 302 header and tell google that the content of www.site.com/info.php?id=123 is temporary moved to www.site.com/404.html (and please come back later).

The correct method is

header ("HTTP/1.0 404 Not Found");

But it will bypass my custom 404 page defined in .htaccess

If you use

header ("HTTP/1.0 404 Not Found");
header("Location: /404.html");

it will still be a 302 header! So, is there a way to send a 404 header and redirect to a custom 404 page inside php source code?

Radiance

4:56 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



header ("HTTP/1.0 404 Not Found 404.html");

iProgram

11:27 am on Mar 19, 2005 (gmt 0)

10+ Year Member



Not work:(
The header code is 404 but no redirect...

jatar_k

4:33 pm on Mar 19, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



all you need to do is include the custom 404 page I would think

if the query returns nothing, include 404 page
else continue processing as is