【问题标题】:Using standard error 404 instead of wordpress 404 - htaccess使用标准错误 404 而不是 wordpress 404 - htaccess
【发布时间】:2016-03-14 12:21:55
【问题描述】:

我想使用标准的服务器 404 页面,而不是通过这个 htaccess 完成的 wordpress 404 重定向页面:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

但我仍然想使用永久链接。有人可以帮我修改 htaccess 文件,我可以恢复服务器的正常错误 404 吗? 谢谢

【问题讨论】:

  • 其实这是不可能的。 htaccess 将所有内容重写到 index.php,因此您的网络服务器永远不会发送 404。您需要修改 wordpress。
  • 可以模拟标准404错误页面...
  • @charlotte:我该怎么做?
  • 在 wordpress 中查找发送 404 页面的代码,并将其替换为您想要查看的内容。
  • 好吧,但它不起作用。我已经设计了错误 404 页面,但谷歌一直在访问我服务器上不存在的旧文件。我认为服务器响应阻止谷歌这样做:(

标签: php wordpress .htaccess mod-rewrite


【解决方案1】:

制作您自己的 404.php 文件并将其放在您的主题文件夹中。这样,您可以让 404 页面看起来像您想要的那样,无论是标准 404 页面:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

或一种风格的主题。

无论哪种方式,请使用控制台或开发工具检查以确保您获得正确的 404 标头。

如果没有,请使用 PHP 发送 404 标头,以便您发送搜索引擎通过使用可以理解的真正 404 响应

&lt;?php header("HTTP/1.0 404 Not Found"); ?&gt;

在 404.php 文件的顶部。

【讨论】:

  • 根据我的经验,并非总是如此;添加详细信息以回答。
  • 就像我上面写的那样,我已经设计了这个文件,但是谷歌一直在访问我服务器上旧的不存在的文件。我认为服务器响应阻止谷歌这样做:(
  • Google 可能会继续这样做,以及其他搜索机器人;创建 sitemap.xml、robots.txt 文件并使用 Google 的网站管理员工具更好地控制 Google 的索引和机器人。
猜你喜欢
  • 2018-06-18
  • 2010-12-17
  • 2021-12-21
  • 2012-09-22
  • 1970-01-01
  • 2017-05-19
  • 1970-01-01
  • 1970-01-01
  • 2015-05-26
相关资源
最近更新 更多