简体   繁体   English

我可以在apache服务器的“自定义404”页面上发送与404不同的标头吗?

[英]Can I send a different header than 404 on my "custom 404' page in an apache server?

Example: 例:

On the custom 404 script/page I want to check the requested uri against a list and redirect the user to that page if the requested uri doesn't exist. 在自定义404脚本/页面上,我想对照列表检查请求的uri,如果请求的uri不存在,则将用户重定向到该页面。

I may send a 301 or a 302 depending on the content in the uri. 我可能会根据uri中的内容发送301或302。

EDIT: 编辑:

Here's the new idea: put the 404 error document in a new directory eg /errors/. 这是一个新想法:将404错误文档放在新目录中,例如/ errors /。 In that directory put the .htaccess with 4500 301 redirects. 在该目录中放入带有4500 301重定向的.htaccess。 That way the 301 redirects are not processed on every root page, but only when a page is not found. 这样,不会在每个根页面上处理301重定向,而是仅在未找到页面时处理。

Please comment if this makes sense. 如果这有意义,请发表评论。

That many redirects i would definitely put in the httpd.conf/apache.conf. 我一定会在httpd.conf / apache.conf中放入这么多重定向。 I would also suggest to redirect with a 301 status code (instead of delivering a 404 and then redirect as you outlined in your question). 我还建议使用301状态代码进行重定向(而不是传递404,然后按照问题中的概述进行重定向)。 That said - there is one exceptional case: if there is a chance to map those 4500 redirects using regexp - you could switch back to htaccess again... 就是说-有一种特殊情况:如果有机会使用regexp映射这些4500重定向-您可以再次切换回htaccess ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM