我最近升级了一个网站,几乎所有 URL 都发生了变化。我已经重定向了所有这些(或者我希望如此),但其中一些可能已经被我忽略了。有没有办法以某种方式捕获所有无效 URL 并将用户发送到某个页面,并以某种方式知道该人来自哪个 URL,以便我可以记录此内容并修复这些问题?我想我可以以某种方式使用 .htaccess 但不知道如何使用。我正在使用 PHP 非常感谢!
您可以使用自定义ErrorDocument http://httpd.apache.org/docs/2.2/en/mod/core.html#errordocument用 PHP 编写的处理程序,用于捕获“漏掉”的 URL:
# .htaccess file
ErrorDocument 404 /not-found.php
And in 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');
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)