如何将 Apache HTTP 代码 404 替换为 200 [英] How can I replace Apache HTTP code 404 to 200

查看:32
本文介绍了如何将 Apache HTTP 代码 404 替换为 200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望网站的 apache 返回任何 HTTP 代码 404,
原因是认证委员会会扫描所有网站,
许多javascript链接和一些事件会导致404代码,
事实上,这些链接是有效的,但该检查器会误判错误.
所以,我想阻止 apache 返回 HTTP 代码 404,
如何配置 apache 返回 HTTP cods 200 而不是 404 并显示我的定义错误页面?

I don't want the apache of a website return any HTTP code 404,
the reason is that the accreditation council will scan all the website,
many javascript links and some incidents will cause the 404 code,
in fact, those links are valid but that checker will misjudge error.
So, i want to prevent the apache to return HTTP code 404,
How can I configure apache return HTTP cods 200 instead of 404 and show my define error page?

推荐答案

来自:http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html

  1. 在您的主 Web 目录中创建一个名为 404.. 的空白文件.
  2. 将此添加到您的 .htaccess 文件中:

  1. Create a blank file in your main web directory named 404.. can be blank.
  2. Add this to your .htaccess file:

Redirect 200 /404
ErrorDocument 404 /404

这会将 Apache ErrorDocument 更改为/404 文件.但是重定向行会导致对/404 的请求发出 200 OK 响应而不是 404.

That will change the Apache ErrorDocument to the /404 file. But the Redirect line causes requests for /404 to issue a 200 OK response instead of a 404.

如果这不起作用,毫无疑问是由于重写.因此,如果是这种情况,请将其添加到前 2 行之下,但在 .htaccess 文件中的任何其他重写行之上:

If that doesn't work it is due to rewrites no doubt. So if that's the case add this under those first 2 lines but above any other rewrite lines in your .htaccess file:

Options FollowSymLinks ExecCGI

RewriteEngine On
RewriteBase /

# If the requested file doesnt exist
# and if the requested file is not an existing directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^4]* /404 [L,S=4000]

更详细的解释:http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#Automate_ErrorDocument_Triggering

这篇关于如何将 Apache HTTP 代码 404 替换为 200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆