的.htaccess重定向到404页的重写规则 [英] .htaccess redirect to 404 page RewriteRule

查看:478
本文介绍了的.htaccess重定向到404页的重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在htaccess文件输入一个重写规则重定向到一个404页如果某个文件夹/ URL路径被键入或达到?

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?

例如,如果我想每一个用户被重定向到一个404页面,如果他们得到: www.mydomain.com/abc或www.mydomain.com/abc/或任何附带ABC后,即使该文件夹真的存在,我不希望用户能够达到它。如果他们这样做实现它,我想让他们看到的404错误页面。 * 的请注意我不是寻求建立一个自定义404错误页面,我正在寻找一种方法来重定向到默认的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. If they do reach it, I want them to see the 404 error page. * 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.

我该怎么办呢?这可能吗?

How can I do it? Is it possible?

RewriteRule ^abc/(*)?$ [R=404,L]

和我怎么能做到同样的事情在PHP中,重定向到一个404错误页面?再次,我不是在谈论设置自定义404页,我说的是默认的404页面,简单地将用户重定向到使用PHP 404错误页面。

And how can I do the same thing in php, redirect to a 404 error page? 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.

推荐答案

使用的mod_rewrite ,您可以用 RedirectMatch 指令:

RedirectMatch 404 ^/abc/.*$

这篇关于的.htaccess重定向到404页的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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