4

I cant understand why but:

RewriteCond %{HTTP_HOST} market\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^market\.mysite\.com$ [NC]
RewriteCond %{REQUEST_URI} \.(png|jpe?g|bmp|gif|swf|css|js)$ [NC]
RewriteRule ^(.*) http://market.mysite.com/$1 [L,R]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Works as expected. Redirecting images to an other domain. But this one:

RewriteCond %{HTTP_HOST} market\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^market\.mysite\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(png|jpe?g|bmp|gif|swf|css|js)$ [NC]
RewriteRule ^(.*) http://market.mysite.com/$1 [L,R]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Will redirect all no matter what. What I want to see is to redirect all except images. What I am trying to do in my rules above is to redirect all sub-domains of market.mysite.com to market.mysite.com if it wasn't market.mysite.com and if it wasn't an image. In another word:

cdn.market.mysite.com -> market.mysite.com

cdn.market.mysite.com/blahblah.html -> market.mysite.com/blahblah.html

cdn.market.mysite.com/blahblah.png -> NO REDIRECT

market.mysite.com -> NO REDIRECT

I use wildcard sub-domain so all of my market sub-sub-domains will use same directory. And then responding to all of requests by one php file. index.php

Thanks,

4

1 回答 1

4

用这个替换你现有的代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{HTTP_HOST} ^[^.]+\.market\.mysite\.com$ [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/+.+?\.(png|jpe?g|bmp|gif|swf|css|js)[\s?] [NC]
RewriteRule ^ http://market.mysite.com%{REQUEST_URI} [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

在不同的浏览器中测试或清除您现有的浏览器缓存。

于 2013-08-26T07:42:12.027 回答