JesseElser Posted January 6, 2015 Share Posted January 6, 2015 So while editing my .HTACCESS file I added the proper lines to redirect users that encounter errors like 404 and 500. It works like a charm if I tell it to display a specific message. However if I tell the file to redirect users to a custom error page it fails. When testing out my 404 redirect I get this: Not Found The requested URL /143/test.php was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80 As you can see it is stating that my ErrorDocument is not found BUT if I type my ErrorDocument URL in I can go to it myself. My .HTACCESS file looks like this: ErrorDocument 400 /error.phpErrorDocument 401 /error.phpErrorDocument 403 /error.phpErrorDocument 404 /error.phpErrorDocument 500 /error.phpErrorDocument 502 /error.phpErrorDocument 504 /error.php # supress php errorsphp_flag display_startup_errors offphp_flag display_errors offphp_flag html_errors off # enable PHP error loggingphp_flag log_errors onphp_value error_log PHP_errors.log NOTE: I am using localhost (WAMP). Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/293711-404-redirect-not-working/ Share on other sites More sharing options...
hansford Posted January 6, 2015 Share Posted January 6, 2015 My .HTACCESS file looks like this: That is not an htaccess file Quote Link to comment https://forums.phpfreaks.com/topic/293711-404-redirect-not-working/#findComment-1501928 Share on other sites More sharing options...
hansford Posted January 6, 2015 Share Posted January 6, 2015 Ugly, but great question - we will find you an answer. Quote Link to comment https://forums.phpfreaks.com/topic/293711-404-redirect-not-working/#findComment-1501929 Share on other sites More sharing options...
CroNiX Posted January 6, 2015 Share Posted January 6, 2015 Is it your application that determines whether it's a 404 page, or the webserver itself? Like for your /143/test.php example, is there an actual directory named 143 with a test.php file in it, or does your app take the request, translate it and look it up in a db for routing or something? If it's the app making the determination, then those ErrorDocument directives will never be used as those are for "native" errors to the webserver. This might be a language problem around the term "redirect", but you should never "redirect" to a 404 page. Redirects change the url and actually take the visitor to a different page. You should just throw a 404 status header and display a custom not found message, but the URL should still be the actual page that is missing and not redirected (a new request) to /errors.php. Otherwise, you are telling browsers and search engines that "http://yoursite.com/errors.php" doesn't exist instead of the actual missing page, which in fact it does. Quote Link to comment https://forums.phpfreaks.com/topic/293711-404-redirect-not-working/#findComment-1501933 Share on other sites More sharing options...
Solution JesseElser Posted January 6, 2015 Author Solution Share Posted January 6, 2015 (edited) I found a solution but I appreciate the replies.First: CroNiX test.php was added to the url to trigger the 404 error since that file does not exist.It turns out that in the .htaccess file I had the urls wrong since I did not realize that it was looking at the root folder. This was solved by simply changing the paths from ErrorDocument 404 /error.php to ErrorDocument 404 /143/error.php Marked as "Best Answer" for anyone else that made a similar mistake. Edited January 6, 2015 by JesseElser Quote Link to comment https://forums.phpfreaks.com/topic/293711-404-redirect-not-working/#findComment-1501938 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.