对现有文件夹/目录给出 404

发布于 2024-09-10 11:27:31 字数 130 浏览 1 评论 0原文

我的根目录中有一个文件夹,我不想让任何人知道。即使有人输入正确,我也想抛出 404 未找到。

也许这可以通过 mod-rewrite 来实现吗?

我现在无法将其存储在根目录之外,不要问为什么

谢谢!

I have a folder in my root that i want no one to know of. Even if someone types in it correct i want to throw a 404 not found.

Would this be Possible to do with mod-rewrite perhaps?

I cant store it outside root right now, dont ask why

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦回梦里 2024-09-17 11:27:31

抛出 403 是不可能的吗?如果您具有 shell 访问权限,则可以 chmod 该目录,以便 Web 用户无法读取或统计它。

Is throwing a 403 out of the question? If you have shell access, you can chmod the directory so the web user cannot read or stat it.

友谊不毕业 2024-09-17 11:27:31

创建自定义 404 页面,然后设置 mod_rewrite 以将对违规目录的请求重写到自定义 404 文件。无论如何,自定义 404 页面通常是一个很好的做法,因此您可以通过这样做以一个的价格获得两个页面。

Create a custom 404 page and then set mod_rewrite up to rewrite requests to the offending directory to the custom 404 file. Custom 404 pages are generally good practice anyway so you get two for the price of one by doing this.

太阳男子 2024-09-17 11:27:31

我首先建议将文件移出网络根目录,除非您有非常充分的理由不这样做(而且我不会轻易相信您这样做)。

如果您不想这样做,请使用 Tristan 的 403 错误建议。 的

<Files /path/to/docroot/nameoffile>
    Order allow,deny
    Deny from all
</Files>

如果你真的不想这样做,你应该能够使用别名将 URL 重定向到不存在的位置:

Alias /nameoffile /path/that/doesnt/exist

同样可以使用 mod_rewrite 完成,

RewriteRule /nameoffile /path/that/doesnt/exist [L]

重写的计算成本更高,但它可能是你 如果您无权访问主服务器配置,则这是唯一的选择。

I'd first suggest moving the file out of the web root, unless you have a really good reason not to (and I won't easily be convinced that you do).

If you're intent on not doing that, use Tristan's suggestion of a 403 error. Something like

<Files /path/to/docroot/nameoffile>
    Order allow,deny
    Deny from all
</Files>

If you're really intent on not doing that, you should be able to use an alias to redirect the URL to a nonexistent location:

Alias /nameoffile /path/that/doesnt/exist

The same could be done with mod_rewrite,

RewriteRule /nameoffile /path/that/doesnt/exist [L]

The rewrite is more computationally expensive, but it might be your only option if you don't have access to the main server configuration.

流殇 2024-09-17 11:27:31

我没有尝试这个,但我想你可以重定向到不存在的东西。

I did not try this, but I guess you could redirect to something that does not exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文