starphp Posted May 14, 2009 Share Posted May 14, 2009 Hi, I wish to show a custom php page, if the requested page is not available instead of showing the "404 Page not found error". For this, I have used the following in .htaccess file & its works fine ErrorDocument 404 http://dev.meetoncruise.com/pagenotfound.php I need to log the reference URL to be logged into the error log for future reference.. I have used some php Server variable but it doesn't return any result..Mostly due to the htaccess redirection.. Can you suggest any method to get the reference URL in the pagenotfound.php page (custom error page) ? Is it possible by making any modifications to htaccess ? Thank You Quote Link to comment https://forums.phpfreaks.com/topic/158113-page-not-found-redirection-to-a-custom-page/ Share on other sites More sharing options...
monkeytooth Posted May 14, 2009 Share Posted May 14, 2009 no the right section of the form for this but,.. here ya go anyway <Files .htaccess> order allow,deny deny from all </Files> ErrorDocument 400 /errorpgs/e_400.php ErrorDocument 401 /errorpgs/e_401.php ErrorDocument 403 /errorpgs/e_403.php ErrorDocument 404 /errorpgs/e_404.php ErrorDocument 500 /errorpgs/e_500.php put that in an .htaccess file in the root of your server. Then customize them accordingly as you desire. Fair warning though. If you are trying to mail yourself with every time the error files are called up you will get a hefty amount of errors. Loading in your inbox. if you link something wrong, or an image isnt found.. it will invoke the mail code wont show the error page but will still invoke the script in it.. Quote Link to comment https://forums.phpfreaks.com/topic/158113-page-not-found-redirection-to-a-custom-page/#findComment-834121 Share on other sites More sharing options...
starphp Posted May 14, 2009 Author Share Posted May 14, 2009 Thank you for your reply Actually I did that step that you suggested to redirect the user to standard error page. But my question is, how can I get the reference URL in the standard error page ( our custom error page).. I have tried with $_SERVER['REQUEST_URI'] but it doesn't return any value. Also tried the wordpress function to get the reference url.. but no value Quote Link to comment https://forums.phpfreaks.com/topic/158113-page-not-found-redirection-to-a-custom-page/#findComment-834165 Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted May 17, 2009 Share Posted May 17, 2009 I think you are looking for $_SERVER['REFERER'] instead of Request URI. But i'm not sure the referer work in a 404 or others error case, and the referer is unreliable because it's provided by the client. You may want to redirect anything that not a file to a php scripts instead to catch up 404. Like that : .htaccess Options +FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ log.php?request=$1 [NC,L] </IfModule> log.php <?php /* Tell the page doesn't exist */ header("HTTP/1.0 404 Not Found"); if (isset($_GET['request'])) { /* Save it in database or somewhere */ } ?> <html> .... </html> Or you may search for a software that read apache logs and display you only the 404 request. Quote Link to comment https://forums.phpfreaks.com/topic/158113-page-not-found-redirection-to-a-custom-page/#findComment-836002 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.