2012-10-27 59 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]