Forum Moderators: phranque

Message Too Old, No Replies

Tried to use my 404 page to rewrite...

         

dualfragment

8:33 pm on Mar 25, 2005 (gmt 0)

10+ Year Member



In PHP, I do the command header("HTTP/1.0 200 OK"); if the URL contains what I want it to. I found this nifty link online that checks your URL for errors. When I enter my main page, it tells me it works fine. When I enter the URL to what I'm trying to use for the rewriting, it just tells me that there was a 404 error, even though I'm sending that header.

When I view the page in my browser, it shows the page that it is supposed to, but it appears that it may not be sending the 200 code, or 404 may be overriding it somehow.

Can anyone help? My site is ALL dynamic, and I need to get rewriting working if at all possible.

sitz

8:43 pm on Mar 25, 2005 (gmt 0)

10+ Year Member



Can you post you rewrite config?

dualfragment

9:20 pm on Mar 25, 2005 (gmt 0)

10+ Year Member



Not really a config, because my host doesn't support mod-rewriting, but heres the PHP script I wrote that is my 404 file:

<?php

$URL = $_SERVER['REQUEST_URI'];
$URL = explode("/", $URL);

if($URL[1] == "lyrics")
{
if(substr($URL[4], -5) == ".html")
{
header("HTTP/1.0 200 OK");
$id = substr($URL[4], 0, -5);
require_once("(URL removed)");
}
else
{
require_once("real404.php");
}
}
else
{
require_once("real404.php");
}
?>

basically it allows me to enter url like /lyrics/blahblah/blahblah2/17.html. It works fine, just the 404 seems to still be passing, for whatever reason.

jdMorgan

9:59 pm on Mar 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I fi Understand your situation, the key here is that there are two transactions. The first is a request to your server with a non-existent URL. Your server returns a 404-Not Found response, which includes the URL of your php script. The client (e.g. browser) then requests your script from that URL in a second HTTP transaction, which generates a 200-OK response.

There are much better solutions, including mod_rewrite. The "404 ErrorDocument redirect method" is responsible for many sites which can't get or stay listed in search engines. It is also a complete violation of the HTTP protocol (which is why it causes these problems w/search). Using 404 ErrorDocument as way to invoke the script that runs your whole site is an awful solution -- and can create an awful mess (Buy me a few beers, and I'll tell you how I really feel about hacks like this). ;)

There's another problem with returning 200-OK for pages which don't exist. That is that the search engines will see your site as having an "infinite" URL-space, and will arbitrarily limit the depth of spidering on your site to avoid getting caught in it forever. This too may hurt your search rankings.

Some search engines explicitly test for this. At least once a year we get threads about "Yahooglemsnask is spidering non-existent pages on my site?" -- They're testing for your server's 404 response (or lack of it).

Try using the server headers checker [webmasterworld.com] in the WebmasterWorld Control Panel -- It will show only the first response from your server. If you are returning a 404 response for pages that exist, expect problems with search performance.

Jim

dualfragment

10:38 pm on Mar 25, 2005 (gmt 0)

10+ Year Member



What do you suggest I do, since my site is ENTIRELY dynamic? (I designed it that way to be easier to manage)

My host doesn't support mod-rewriting :(

jdMorgan

1:12 am on Mar 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you really want to redirect non-existent URLs to your script, then you need a new host.

But I'm also saying it's not wise to do so, unless you don't care about being well-listed in search.

So, do you see a 404-Not Found response with the WebmasterWorld server headers checker?

Jim

dualfragment

1:46 am on Mar 26, 2005 (gmt 0)

10+ Year Member



Yes, I do, unfortunately.

Don't have cash right now to find a different host. I'm using GoDaddy and only paying 4 bucks a month :(