.htaccess 按文件类型限制访问

发布于 2024-10-04 14:09:26 字数 114 浏览 0 评论 0原文

我对 .htaccess 文件没有太多经验,我想要一个禁止访问(403 Forbiden)文件夹及其所有子文件夹中的 .myext 文件的文件。

谁能给我写一个快速规则吗?

I don't have too much experience with .htaccess files and I would like one that disallows access (403 Forbiden) to .myext files in a folder and all its sub-folders.

Can anyone write me a quick rule?

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

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

发布评论

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

评论(1

開玄 2024-10-11 14:09:26

您可以使用 拒绝

<FilesMatch "\.myext$">
    Deny from all
</FilesMatch>

您可能还需要更改的顺序<应用 code>Allow 和 Deny 规则

另一种选择是使用 mod_rewrite

RewriteEngine on
RewriteRule .+\.myext$ - [F]

仅应用这些指令对于特定目录,将它们放入该特定目录的 .htaccess 文件中。使用 mod_rewrite 您还可以在规则模式中指定路径,例如:

RewriteRule ^foo/bar/.+\.myext$ - [F]

You can use <FilesMatch> and Deny:

<FilesMatch "\.myext$">
    Deny from all
</FilesMatch>

You also might need to change the order of how Allow and Deny rules are applied.

Another option would be to use mod_rewrite:

RewriteEngine on
RewriteRule .+\.myext$ - [F]

To have these directives only be applied on specific directories, put them into the .htaccess file of that specific directory. With mod_rewrite you could also specify the path within the rule pattern like:

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