need help from some professional how to redirect old or invalid url
I recently upgraded a site and almost all URLs have changed. I have redirected all of them (or so I hope) but it may be possible that some of them have slipped by me. Is there a way to somehow catch all invalid URLs and send the user to a certain page and somehow know what URL the person came from so I could log this, and fix those? I'm thinking I could use .htaccess somehow but am not sure how. I am using PHP Thanks so much!
error file is already in .htaccess but seems nothing going to change you can see the error file as below
AddHandler application/x-httpd-php5s .php
ErrorDocument 404 /content/404.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
to see the problem what i want result is i need some thing to redirect if some one types wrong url just check the link even if you delete half of the location at the endof url it still opens http://adsbuz.com/classifieds/abu-dhabi-uae/
it sholud go to the error page but its not giong i neeed some kind force to push it to error page thanks
Solution 1:
You can create a custom 404 file. Assuming you are using Apache you would add the following line to your .htaccess
ErrorDocument 404 /errorfilename.php
This code basically tells the server that if a user encounters a 404(Page not Found) Error to display errorfilename.php.
In this PHP file you can add either code to email you when a user gets to the 404 page or add other logic to support
- Database storage
- Writing to a file/custom log
- searching a database for the file location and redirecting the user to the new destination
In PHP to get the location of the 404 page you would use the following global variable
$_SERVER['HTTP_REFERER']
Example of your 404.php page
<?php
$referer = $_SERVER['HTTP_REFERER'];
//this is where you would either email yourself the $referer,
//insert it into a database or perform more complex operations.
?>
<html>
<head>
<title>404</title>
<body>
Sorry, the page you are looking for has been moved/deleted.<br>
The system administration has been notified of this error.<br>
<a href="index.php">Go to Homepage</a>
</body>
</html>