[英]Prevent access to URL with htaccess with condition
I have an url : 我有一个网址:
https://abc.sitetest.com/images/abc/img.jpg
We read the subdomain from url which is abc
. 我们从url读取子域
abc
。 Using htaccess, we only allow the user to view abc and its subfolder. 使用htaccess,我们仅允许用户查看abc及其子文件夹。 So if there's a folder
/images/cde/...
they can't view or read any file (not an image) in it. 因此,如果有一个文件夹
/images/cde/...
它们将无法查看或读取其中的任何文件(不是图像)。
It could be this but I'm not sure it's the way... 可能是这样,但我不确定是不是...
<Limit GET>
order deny,allow
deny from all
allow from abc.sitetest.com
</Limit>
Place this back reference based rule in your root .htaccess: 将此基于后向引用的规则放在您的根.htaccess中:
RewriteEngine On
RewriteCond %{HTTP_HOST}:%{REQUEST_URI} ^([^.]+)\.[^:]+:(?!.*?/\1/).* [NC]
RewriteRule ^ - [F]
This will allow: 这将允许:
https://abc.sitetest.com/images/abc/img.jpg
https://abc.sitetest.com/anything/abc/foo
but will block: 但会阻止:
https://abc.sitetest.com/images/xyz/img.jpg
https://abc.sitetest.com/def/img.jpg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.