如何阻止来自某些国家/地区的访问者访问我的网站 (xyz.com/thisFile.php) 上的文件?

发布于 2024-12-07 13:39:57 字数 601 浏览 0 评论 0原文

我需要阻止来自某些国家/地区的访问者上传图像 - 但他们应该能够访问该网站。

例如,我有一个网站 xyz.com。按照我当前的设置方式,来自黑名单国家/地区的所有访问者都无法访问该网站本身,并且会收到 403 错误消息。当然,这不是一个好的解决方案,所以我想要进行设置,以便这些用户仍然可以访问和使用该网站,但无法上传图像(通过单击 xyz.com/upload/ 这是 xyz.com/upload_file.php 的别名) 。来自其他白名单国家/地区的所有其他用户显然都应该能够使用该网站的所有功能,但来自黑名单国家/地区的用户除外,他们不应该能够上传其图像。

我如何通过 .htaccess 确保情况如此?我目前在Cloudflare,.htaccess中的相关文本如下:

SetEnvIf CF-IPCountry AA UnwantedCountry=1
SetEnvIf CF-IPCountry BB UnwantedCountry=1
SetEnvIf CF-IPCountry CC UnwantedCountry=1
Order allow,deny
Deny from env=UnwantedCountry
Allow from all

谢谢。

I need to block visitors from certain countries from uploading images - but they should be able to access the site.

For e.g. I've a site xyz.com. The way I have it set up currently, all visitors from blacklisted countries are unable to access the site itself, and are greeted with a 403. This isn't a good solution, of course, so I want to set it up such that these users can still access and play around with the site, but NOT be able to upload images (which is through clicking on xyz.com/upload/ which is an alias for xyz.com/upload_file.php). Every other user from other whitelisted countries should obviously be able to use all of the site's functionalities, save for users from blacklisted countries, who should not be able to upload their images.

How could I ensure this is the case through .htaccess? I am currently on Cloudflare, and the relevant text in .htaccess is as follows:

SetEnvIf CF-IPCountry AA UnwantedCountry=1
SetEnvIf CF-IPCountry BB UnwantedCountry=1
SetEnvIf CF-IPCountry CC UnwantedCountry=1
Order allow,deny
Deny from env=UnwantedCountry
Allow from all

Thanks.

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

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

发布评论

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

评论(3

你好,陌生人 2024-12-14 13:39:57

将问题中的这些代码行更改为:

<Files "upload_file.php">
SetEnvIf CF-IPCountry AA UnwantedCountry=1
SetEnvIf CF-IPCountry BB UnwantedCountry=1
SetEnvIf CF-IPCountry CC UnwantedCountry=1

Order allow,deny
Allow from all
Deny from env=UnwantedCountry
</Files>

这将限制对这些国家/地区的访问仅限于文件 upload_file.php

Change those lines of code in your question with this:

<Files "upload_file.php">
SetEnvIf CF-IPCountry AA UnwantedCountry=1
SetEnvIf CF-IPCountry BB UnwantedCountry=1
SetEnvIf CF-IPCountry CC UnwantedCountry=1

Order allow,deny
Allow from all
Deny from env=UnwantedCountry
</Files>

This will restrict access to those countries only to the file upload_file.php.

无远思近则忧 2024-12-14 13:39:57

它必须是别名吗?您可以创建一个 upload/ 文件夹,并将 .htaccess 放入其中吗?它可能需要更改一些 upload_file.php 逻辑,但这对我来说似乎是最简单的修复方法。

Does it have to be an alias? Could you just create an upload/ folder, and put the .htaccess in there? It might require changing some of the upload_file.php logic, but that seems like the easiest fix to me.

糖果控 2024-12-14 13:39:57

我认为 .htaccess 文件可以放入 /any/ 子目录中。将文件上传代码移动到目录中并将 .htaccess 控件放在那里?

I think .htaccess files can be put into /any/ subdirectory. Move your file uploading code into a directory and put .htaccess controls there?

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