.htaccess:允许来自subdir的iframe只能从root目录查看

时间:2012-02-28 17:07:35

标签: php .htaccess

我有一个网站,我有一个子文件夹,那里有我希望嵌入索引页面的文件。但我希望privent用户直接查看该子文件夹。

因此。我有http://mysite.com/index.php,其中有一个iframe:

我有一个带有index.php的子文件夹opt2和iframe:

<iframe src="http://mysite.com/opt2/" id="shopIframe" name="shopIframe" onload="alert('a');" frameborder="0" height="90%" width="100%" scrolling="auto"></iframe>

我有一个.htaccess文件:

RewriteEngine on
RewriteCond %{HTTP_REFERER} http://mysite.com/opt2/ [NC]
RewriteRule /*$ http://mysite.com/index.php [R=302,L]

是否可以使用.htacces?

1 个答案:

答案 0 :(得分:1)

引荐来源为http://mysite.com/index.php,而不是http://mysite.com/opt2/

此外,一些防火墙软件,代理等删除了引用者标题,因此您最好首先检查引用是否可用。

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://mysite\.com/ [NC]
RewriteRule ^opt2/ http://mysite.com/index.php [R=302,L]

<强>除了

<script>
if( self == top )
  location.href='/index.php';
</script>
相关问题