0

したがって、セキュリティ上の理由から、許可しないようにしたいのですhttp://www.domain.com/directory/が、その物理ディレクトリはhttp://subdomain.domain.com/directory/

簡単な方法はディレクトリを移動することですが、アプリケーションが破損するため移動できません。.htaccessを使用してこれを行うにはどうすればよいですか?

以下を使用して一時的にブロックしました:

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

しかしもちろん、どちらの場合もサブディレクトリをリダイレクトするので、私が思うのは、次のように置くことができるということです。

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

または類似したものですが、機能しません...提案?

4

1 に答える 1

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>

.htaccessApacheがファイルを解析する必要がない場合は、より効率的です。

于 2010-07-23T21:49:34.673 に答える