2010-07-23 57 views
0

所以为了安全起见,我想只有通过http://subdomain.domain.com/directory/的.htaccess:通过一个子块物理目录URL,但允许URL间接

简单的方法来禁止http://www.domain.com/directory/但允许物理目录是只动目录,但我不能这样做,因为它打破了应用程序,所以我怎么用.htaccess来做到这一点?

RedirectMatch 301 ^/directory/$ http://www.domain.com/ 

当然,但是,在这两种情况下重定向的子目录,所以我觉得什么是我可以只是把:

我使用暂时受阻它

RedirectMatch 301 ^http://www.domain.com/directory/$ http://www.domain.com/ 

或类似的东西,但它不工作...建议?

回答

0

您可以用RewriteCond做到这一点:

RewriteEngine on 
RewriteCond %{HTTP_HOST} !subdomain.domain.com 
RewriteRule ^directory http://www.domain.com [R=301] 

虽然更好,但我会建议创建具有相同的文档根另一个虚拟主机。因此,在你的主服务器配置,你必须

<VirtualHost *:80> 
    # this is the existing virtual host for the www subdomain 
    ServerName www.domain.com 
    ... 
    DocumentRoot /path/to/docroot 
    # Add this next section 
    <Directory /path/to/docroot/directory> 
     Options allow,deny 
     Deny from all 
    </Directory> 
</VirtualHost> 
<VirtualHost *:80> 
    # this is the existing vhost for the other subdomain 
    ServerName subdomain.domain.com 
    ... 
    DocumentRoot /path/to/docroot 
</VirtualHost> 

这是当没有配置Apache解析.htaccess文件更有效。