.htaccess和mod_rewrite |总是使用www。虚拟子域的例外

时间:2013-06-04 16:02:18

标签: .htaccess mod-rewrite subdomain

我正在使用.htaccess和mod_rewrite强制始终“www。”在URL中 - 当然也包括其他内容。这是我的.htaccess文件的一部分:

RewriteCond %{REQUEST_URI} !\/images\/ [NC] [OR] 
RewriteCond %{HTTP_HOST} !^www.example\.com$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} index\.php [NC]
RewriteRule ^index\.php$ http://www.example.com/ [NC,R=301]

RewriteRule ^images/([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+).jpg$ pic.php?picID=$1&width=$2&height=$3&corners=$4 

现在我期待使用虚拟子域来加速图像加载(例如:img1。,img2。等)。原因是我的一些页面上有很多缩略图。

但是当我尝试通过虚拟子域加载图像时总是这样 - 例如:

http://img1.example.com/images/672_1000_0_0.jpg

我得到类似的东西:

http://www.example.com/pic.php?picID=672&width=1000&height=0&corners=0

我非常感谢解决我的问题。提前谢谢!

1 个答案:

答案 0 :(得分:0)

我最近遇到了类似的问题,诀窍是使用额外的RewriteCond子句(在2.行上):

RewriteCond %{HTTP_HOST} !^img1.example.com$ [NC] [OR]
RewriteCond %{HTTP_HOST} !^img2.example.com$ [NC] [OR]
RewriteCond %{HTTP_HOST} !^img3.example.com$ [NC] [OR]

如果您拥有无限的虚拟子域,最好直接用正则表达式替换它,例如:

RewriteCond %{HTTP_HOST} !^img([0-9]+).example.com$ [NC] [OR]

希望有所帮助!

相关问题