您可以使用ErrorDocument用PHP编写的自定义处理程序来捕获"滑过"的URL:
# .htaccess file
ErrorDocument 404 /not-found.php
Run Code Online (Sandbox Code Playgroud)
并在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');
}
Run Code Online (Sandbox Code Playgroud)