2012-10-27 58 views
0

特定擴展名的我有一個域名abc.com允許域名只爲有hatccess

使用子

abc.com 
www.abc.com 
img.abc.com 

所有指向我的服務器上的同一個文件夾。

由於我打算使用img.abc.com作爲cdn,因此需要防止img.abc.com/pqr.html成爲www.abc.com/pqr.html的副本。

abc.com/* should redirect to www.abc.com/* 
img.abc.com/*.jpg/gif/png should be allowed 
[img.abc.com/*.other extension] should be redirected to [www.abc.com/*.other extension] 

可能是什麼可能htaccess的規則被列入?

回答

0

添加這些規則的htaccess文件你的文檔根:

RewriteEngine On 

# abc.com/* should redirect to www.abc.com/* 
RewriteCond %{HTTP_HOST} ^abc\.com$ [NC] 
RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R] 

# img.abc.com/*.jpg/gif/png should be allowed 
RewriteCond %{HTTP_HOST} ^img\.abc\.com$ [NC] 
RewriteRule \.(jpe?g|png|gif)$ - [L,NC] 

# [img.abc.com/*.other extension] should be redirected to [www.abc.com/*.other extension] 
RewriteCond %{HTTP_HOST} ^img\.abc\.com$ [NC] 
RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R]