配置只允许特定域使用 .htaccess 访问某些文件夹 [英] configure only allow specific domains to access certain folders using .htaccess
问题描述
我有如下场景:
例如,我有一个网站 http://www.example.com
,并且我设置了一些子域,例如 http://video.example.com代码>、<代码>http://image1.example.com
、http://image2.example.com
.在 Apache 虚拟主机设置中,它们使用相同的文件夹(例如 /home/example/
).(这两个域使用 mod_cband 具有不同的带宽设置).
For example,I have a website http://www.example.com
, and I have setup a few subdomains such as http://video.example.com
, http://image1.example.com
, http://image2.example.com
. In Apache virtual host setting, they are using the same folder (e.g. /home/example/
). (these two domains have different bandwidth setup using mod_cband).
我有一个子文件夹 /home/example/files/videos
,我想让它只能从子域 http://video.example.com/files/videos/访问
但不是来自 http://www.example.com/files/videos/
或任何其他子域.
I have a subfolders /home/example/files/videos
, I want to make it only accessible from the subdomain http://video.example.com/files/videos/
but not from http://www.example.com/files/videos/
or any other subdomains.
我应该如何使用 .htaccess
文件配置它?
How shall I configure this with a .htaccess
file?
推荐答案
把这段代码放在/home/mywebsite/files/videos/.htaccess
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /files/videos/
# if it is not for domain video.mywebsite.com then block it
RewriteCond %{HTTP_HOST} !^video\.mywebsite\.com$ [NC]
RewriteRule ^ - [F]
这篇关于配置只允许特定域使用 .htaccess 访问某些文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!