Jump to content

Custom error pages...


skoobi

Recommended Posts

Hi im a little stuck... What im trying to do is when you request a page that is not there it goes to a custom error page. I have set the redirect via the .htaccess file.

 

Basicly what im trying to do is only have one php file which displays the server response i.e. 404 error or 401 error and so on rather than having several error pages.

 

So in the code

<h1>Oopppsss!!!! <!-- ERROR TO DISPLAY HERE i.e. 404 page not found --></h1>
      <p>There seems to be a problem... The page you are looking for does not exist or has moved. This is a permanent error. If you think this is a mistake please get in touch either by giving us a ring on 101010 or by filling out the web form on the <a href="contact-me.php">contact me</a> page...</p>

 

Any thaught on how i can do this or is it not possible...

 

Cheers

 

Link to comment
Share on other sites

Hi sorry.. ive already done that but id have to make a file for all the errors i.e 404, 401, 500 and so on... i was just wondering if there was a way to use 1 file called error and display the error on there ... not sure if it is possible or not...

Thank you for you reply

Link to comment
Share on other sites

I don't think it can be done. What htaccess does is just a redirect to the specified file when the error occurs, but it's the file's job to send the actual headers. If htaccess redirected a 404 error to 404.php, it's 404.php's job to construct a header("HTTP/1.0 404 Not Found"). There's no way, as far as I know, to check what type of error the visitor was redirected from.

 

Honestly, it's such an unimportant thing that you shouldn't stress yourself out. It just needs 4 or 5 files for the most common http headers.

Link to comment
Share on other sites

Can you add a query string in the .htaccess file? I don't know if it is supported or not and I don't have access to an environment here to try it.

 

ErrorDocument 404 /errorDoc.php?status=404
ErrorDocument 401 /errorDoc.php?status=401

 

Also, when using mod_rewrite, I notice that there are additional keys in the $_SERVER array indicating the original request and the redirected request. You might try looking at what is in $_SERVER when you reach the error page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.