【发布时间】:2015-04-01 06:33:08
【问题描述】:
我正在使用 apache 服务器,请考虑这是我的网站:www.domain.com。
我将所有文件、图像、视频保存在子域中,例如-> http://sub.domain.com/file.jpg
我正在访问子域中的所有文件(即图像、视频)。
如果有用户直接在地址栏(http://sub.domain.com/file.jpg)绑定访问我的文件,它应该显示 403 禁止页面。
如果有任何用户想要访问我的网站(www.domian.com),它应该允许访问。
我尝试了以下 .htaccess 代码,
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?sub.domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?sub.domain.com.*$ [NC]
RewriteRule \.(gif|jpg|png|avi|mp3|swf")$ - [F]
但问题是,当我访问我的网站时,它也会给出 403 禁止结果。
更新:
index.html in (domain.com)
<html>
<body>
<h1>Example Page</h1>
<img src="http://sub.domain.com/file.jpg">
</body>
</html>
输出:(当我尝试访问“domain.com”时)
Example Page
图片未加载。它在“控制台”中显示 403 禁止。
【问题讨论】:
标签: apache .htaccess mod-rewrite http-status-code-403