自定义 404 页面上的相关链接

Relative links on a custom 404 page

我的网站上有一个个性化的 404 错误页面,

ErrorDocument 404 404.htm

在我的 .htaccess.

问题是,如果您键入 www.mydomain.com/whatever/whatever2.html,它会正确显示 404 页面,但是 link 全部损坏,例如 link 到 href="property.php" 指向 www.mydomain.com/whatever/property.php,这也是一个 404 错误。

如何在不将所有路由更改为绝对路由的情况下解决此问题?

您可以在页面 HTML 的 <head> 部分添加此内容:<base href="/" /> 这样每个 亲戚 URL从该基础 URL 而不是当前页面的 URL.

解析

而不是像这样使用相对路径:

href="property.php"

尝试使用绝对路径,例如:

href="http://www.example.com/path/to/property.php"
 <base href="/"> 

不适用于 google Adsense/Analytics。除零。

因为错误 404 页面必须能够 运行 来自任何 URL 我的 404.php 只包含

<?php
header("Location: http:/homepage.de");
?>

这样它就重新定位到基地URL。