使用 .htaccess 限制对文件的访问

发布于 2025-01-04 17:18:38 字数 248 浏览 3 评论 0原文

我在同一帐户上托管了 2 个域,但我想限制第二个域不访问文件。

我有 abc123.com 和 zyx987.com。

在我的 php 中,我做了所有需要的事情来显示域名和基于域的模板,但我只想从 abc123.com 访问 /download 文件。

下载文件夹包含以下文件:file1.pdf 或 file2.zip。

我尝试了“拒绝所有人”,但这不起作用,因为其他域也被阻止了。

还有别的办法吗?

I have 2 domains hosted on the same account but I want to restrict the second one to not access files.

I have abc123.com and zyx987.com.

In my php I do everything I need to display the domain name and template based on the domain but I want only the /download files to be accessed from abc123.com.

The download folder has files like: file1.pdf or file2.zip.

I tried the 'deny from all' but this didnt work since the other domain is blocked too.

Is there another way?

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

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

发布评论

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

评论(1

断桥再见 2025-01-11 17:18:38

这是你必须做的。将其放入您的 .htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?zyx987.com$
RewriteRule ^download - [F]

这将阻止任何请求,例如:

/download/
/download/file1.jpg
/download/another/file.zip

并拒绝许可。

Here's what you have to do. Put this in your .htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?zyx987.com$
RewriteRule ^download - [F]

This will block any request like:

/download/
/download/file1.jpg
/download/another/file.zip

and give a permission denied.

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