如何使用htaccess将带有404响应代码的404错误页面重定向到自定义页面

问题描述:

我想将404错误页面重定向到自定义404页面.例如,如果 http://example.com/abc.html 导致404错误,我想重定向页面到 http://example.com/404.html ,其中包含404 http响应代码.有可能吗?

I want to REDIRECT 404 error page to custom 404 page. For example, if http://example.com/abc.html causes 404 error, I want redirect the page to http://example.com/404.html with 404 http response code. It is possible?

到目前为止,尚无选择将404错误页面重定向到带有404 http响应代码的自定义404页面.要获取404 http响应代码,您将需要显示自定义404错误页面内容而不进行重定向,例如以下代码:

So far there is NO OPTION to redirect 404 error page to a custom 404 page with 404 http response code. To get 404 http response code, you will need to display custom 404 error page content without redirection like following code:

ErrorDocument 404 /404.html

如果您使用以下代码,则会将404错误页面重定向到具有302 http响应代码的自定义404页面

And if you use following code, the 404 error page will be redirected to the custom 404 page with 302 http response code

ErrorDocument 404 http://www.yourdomain.com/404.html