2013-05-31 8 views
7

.htaccessを使用して特定のフォルダにアクセスすることを許可:configureは、特定のドメインが、私は次のようなシナリオが午前

は、例えば、私はウェブサイトhttp://www.example.comを持っているが、私はセットアップいくつかのサブドメインを持っているようなhttp://video.example.comhttp://image1.example.comhttp://image2.example.com 。 Apacheの仮想ホスト設定では、同じフォルダ(例:/home/example/)を使用しています。 (これらの2つのドメインは、mod_cbandを使用して異なる帯域幅設定を持っています)。

私はサブフォルダ/home/example/files/videosを持って、私はhttp://www.example.com/files/videos/または任意の他のサブドメインからサブドメインhttp://video.example.com/files/videos/からそれだけでアクセスできるようにしたいが、ない

.htaccessファイルでこれを設定するにはどうすればよいですか?

+0

にこのコードを入れてください参照者が信頼できないため、rrerは引用符で囲んだ最も一般的な "解決策"です。 – CBroe

答えて

12

は​​REFEをチェック

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] 
-2
rewritecond %{HTTP_HOST} video.mywebsite.com [s=1] 
rewriterule files/videos/.* - [F] 
2

あなたがホストをチェックして、mod_rewrite.htaccessファイルで301リダイレクトを作成し、これを処理することができます。アクセス権がある場合は、httpd.confまたは含まれている設定ファイルでこれを行う方がはるかに優れています。 mod_cbandは、ドメインごとに異なるvirtualhostを望んでいるように見えるので

ベストシナリオ

は、セットアップ、このようなあなたのhttpd.confファイルに何かをだろうし、設定自体に書き換えルールが含まれます。アップ

<VirtualHost *:80> 
    ServerName www.mywebsite.com 
    DocumentRoot /home/mywebsite/ 

    RewriteEngine on 
    RewriteRule ^/files/videos/(.*)$ http://video.mywebsite.com/$1 [R=301,L] 
    RewriteRule ^/files/images1/(.*)$ http://image1.mywebsite.com/$1 [R=301,L] 
    RewriteRule ^/files/images2/(.*)$ http://image2.mywebsite.com/$1 [R=301,L] 

</VirtualHost> 

<VirtualHost *:80> 
    ServerName video.mywebsite.com 
    DocumentRoot /home/mywebsite/files/video/ 
</VirtualHost> 

<VirtualHost *:80> 
    ServerName image1.mywebsite.com 
    DocumentRoot /home/mywebsite/files/images1/ 
</VirtualHost> 

<VirtualHost *:80> 
    ServerName image2.mywebsite.com 
    DocumentRoot /home/mywebsite/files/images2/ 
</VirtualHost> 

ランナーあなたはホスティングサービスプロバイダを使用している場合:メインアカウントサイトはDocumentRootであり、それは、ディレクトリの下に他のサイトには、すべてのネストされているところ、一部のWebホストは、このメソッドを実行しますあなたはhttpd.confファイルにアクセスできないが、メインドメインのalias(各ドメインには別々のフォルダがある)としてドメインを設定していない場合は、ルートに.htaccessのルールを書くと、www.mywebsite.comのようになりますこれは:

RewriteEngine On 
    RewriteRule ^(files/videos/.*)$ http://video.mywebsite.com/$1 [R=301,L] 
    RewriteRule ^(files/images1/.*)$ http://image1.mywebsite.com/$1 [R=301,L] 
    RewriteRule ^(files/images2/.*)$ http://image2.mywebsite.com/$1 [R=301,L] 

ほとんどオーバーヘッド

彼らは(すべてが正確に同じドキュメントルートを持っている)のエイリアスを使用している場合は、一般的にすべてによって制定されています.htaccessファイルを要求されたホスト名をチェックする必要があります

RewriteEngine On 
RewriteCond %{HTTP_HOST} !^video.mywebsite.com$ 
RewriteRule ^(files/videos/.*)$ http://video.mywebsite.com/$1 [R=301,L] 

    #Check to make sure if they're on the video domain 
    #that they're in the video folder otherwise 301 to www 
    RewriteCond %{HTTP_HOST} ^video.mywebsite.com$ 
    RewriteCond %{REQUEST_URI} !^/files/videos [NC] 
    RewriteRule ^.*$ http://www.mywebsite.com/ [R=301,L] 


RewriteCond %{HTTP_HOST} !^image1.mywebsite.com$ 
RewriteRule ^(files/images1/.*)$ http://image1.mywebsite.com/$1 [R=301,L] 

    #Check to make sure if they're on the image1 domain 
    #that they're in the images1 folder 
    RewriteCond %{HTTP_HOST} ^image1.mywebsite.com$ 
    RewriteCond %{REQUEST_URI} !^/files/images1 [NC] 
    RewriteRule ^.*$ http://www.mywebsite.com/ [R=301,L] 

RewriteCond %{HTTP_HOST} !^image2.mywebsite.com$ 
RewriteRule ^(files/images2/.*)$ http://image2.mywebsite.com/$1 [R=301,L] 

    #Check to make sure if they're on the image1 domain 
    #that they're in the images2 folder 
    RewriteCond %{HTTP_HOST} ^image2.mywebsite.com$ 
    RewriteCond %{REQUEST_URI} !^/files/images2 [NC] 
    RewriteRule ^.*$ http://www.mywebsite.com/ [R=301,L] 
関連する問題