skoobi Posted August 21, 2011 Share Posted August 21, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/245363-custom-error-pages/ Share on other sites More sharing options...
codefossa Posted August 21, 2011 Share Posted August 21, 2011 Edit / Create a .htaccess file and add something like: ErrorDocument 404 /404.html Quote Link to comment https://forums.phpfreaks.com/topic/245363-custom-error-pages/#findComment-1260222 Share on other sites More sharing options...
skoobi Posted August 22, 2011 Author Share Posted August 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/245363-custom-error-pages/#findComment-1260667 Share on other sites More sharing options...
Fadion Posted August 23, 2011 Share Posted August 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245363-custom-error-pages/#findComment-1260733 Share on other sites More sharing options...
skoobi Posted August 23, 2011 Author Share Posted August 23, 2011 Ye just a thaught thats all. I didnt think it could be done... Ive just created a error page that is global to everything instead ... Thanks for your help though... Cheers Quote Link to comment https://forums.phpfreaks.com/topic/245363-custom-error-pages/#findComment-1260993 Share on other sites More sharing options...
DavidAM Posted August 23, 2011 Share Posted August 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245363-custom-error-pages/#findComment-1261001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.