Jump to content

Page not found redirection to a custom page


starphp

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.