0

我有一个域 abc.com

带有子域

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

都指向我服务器上的同一个文件夹。

由于我打算将 img.abc.com 用作 cdn,因此需要防止 img.abc.com/pqr.html 与 www.abc.com/pqr.html 重复。

IE

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 规则?

4

1 回答 1

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]
于 2012-10-27T13:58:18.683 回答