[英].htaccess redirect to 404 page RewriteRule
Is there a way to enter a RewriteRule in the htaccess file to redirect to a 404 page if a certain folder/url path as been typed or reached? 有没有办法在htaccess文件中输入RewriteRule,以便在键入或到达某个文件夹/ url路径时重定向到404页面?
For example, if I want every user to be redirected to a 404 page if they get to: www.mydomain.com/abc or www.mydomain.com/abc/ or whatever that comes after "abc", even if that folder really exists, I do not want the users to be able to reach it. 例如,如果我希望每个用户都被重定向到404页面,如果他们到达:www.mydomain.com/abc或www.mydomain.com/abc/或“abc”之后的任何内容,即使该文件夹确实如此存在,我不希望用户能够访问它。 If they do reach it, I want them to see the 404 error page.
如果他们确实达到了,我希望他们看到404错误页面。 * Please note I am not looking to set up a custom 404 error page, I am looking for a way to redirect to the default 404 page.
*请注意我不打算设置自定义404错误页面,我正在寻找一种方法重定向到默认的404页面。
How can I do it? 我该怎么做? Is it possible?
可能吗?
RewriteRule ^abc/(*)?$ [R=404,L]
And how can I do the same thing in php, redirect to a 404 error page? 我怎么能在PHP中做同样的事情,重定向到404错误页面? Once again I am not talking about setting a custom 404 page, I am talking about the default 404 page, to simply redirect a user to the 404 error page using php.
我再一次不是在谈论设置自定义404页面,我在谈论默认的404页面,只是使用php将用户重定向到404错误页面。
您可以使用RedirectMatch
指令执行此操作,而不是使用mod_rewrite
:
RedirectMatch 404 ^/abc/.*$
I did this on my website: 我在我的网站上这样做了:
RewriteRule ^404/?$ 404.php
ErrorDocument 404 http://www.example.com/404/
And on the root of my website I placed a 404.php
page to customize that page. 在我的网站的根目录上,我放置了一个
404.php
页面来自定义该页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.