Jump to content
Sign in to follow this  
rklau

404 Using Php Instead Of Shtml?

Recommended Posts

Hi -

 

I have a snippet of php code I want to execute in my 404 page. I have created a custom 404 page through cPanel, assigned the filename of 404.php at the bottom, and confirmed that (a) the file is written properly and (B) when accessed directly (i.e., www.rklau.com/404.php) it works fine.

 

But when you access a page that doesn't exist, I get this:

 

The requested URL /foo was not found on this server.

 

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

 

I tried manually updating .htaccess with this:

 

ErrorDocument 404 /home/xxxxx/public_html/404.php

 

But that is what seems to generate the error message above.

 

So - how do I direct 404's to 404.php instead of 404.shtml?

 

--Rick

Share this post


Link to post
Share on other sites

That's odd... I think it should work. :whip:

 

Try using a relative path to the file instead - instead of using

 

ErrorDocument 404 /home/xxxxx/public_html/404.php

 

use just

 

ErrorDocument 404 404.php

Share this post


Link to post
Share on other sites

Sorry, but that doesn't work either. Now I get this:

 

The requested URL /foo was not found on this server.

 

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

 

I'm stumped...

Share this post


Link to post
Share on other sites

Well, fool around enough with something and you can make it work. Turns out the line has to read:

 

ErrorDocument 404 /404.php

 

Go figure.

 

For those who are interested, I implemented this hack in Movable Type:

 

http://www.rklau.com/tins/archives/2003/12...mtrefsearch.php

 

Which lets me capture incoming referral links to help people find what they want on my blog; now the 404 page includes the same code. (I'm going to have to modify the 404 one a bit to include both blogs hosted at my domain, but you get the idea.)

 

Now, when they get referred to a non-existent page from a search engine, the first thing the 404 page does is execute a query against my blogs - if there are posts that contain the search strings used at the search engine, it will present links to those posts before just presenting the visitor with a standard search interface.

 

--Rick

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...