I recently updated the site and almost all of the URLs have changed. I redirected them all (or I hope), but it is possible that some of them slipped. Is there a way to somehow catch all the invalid URLs and send the user to a specific page and somehow find out which URL the person came from so that I can register this and fix it? I think I can use .htaccess somehow, but I don’t know how to do it. I am using PHP. Many thanks!
You can use a custom ErrorDocumenthandler written in PHP to catch URLs that have "slippable":
ErrorDocument
# .htaccess file ErrorDocument 404 /not-found.php
And in not-found.php:
not-found.php
switch($_SERVER['REDIRECT_URL']) { case '/really_old_page.php': header('HTTP/1.1 301 Moved Permanently'); header('Location: /new-url/...'); /* As suggested in the comment, exit here. Additional output might not be handled well and provokes undefined behavior. */ exit; default: header('HTTP/1.1 404 Not Found'); die('404 - Not Found'); }
.htaccess -
ErrorDocument 404 /yourFile.php
404 htaccess.
- :
ErrorDocument 404 /errors/404.php
in .htaccess (create it if necessary) in the root of the application. And all requests to any other pages will be redirected to your own 404 page.
Source: https://habr.com/ru/post/1786254/More articles:Social Network PHP / MySQL Structure - phpJava: Does anyone have an example project using Google protocol buffers over a network? - javaCopy the database from one server to another using C # - c #Как получить NTWDBLIB.DLL в виде 64-битного файла - 64bitAero Glass extension in F # (PInvoke) - f #connecting to PostgreSQL over a network - databasePowerbuilder - How to create class properties - powerbuilderSolr - schema help (product attributes) - mysqlOverwrite ajaxComplete for a specific ajax request - jqueryDisabling ALL asynchronous execution in CUDA programs - asynchronousAll Articles