Redirect everything except images

I can’t 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] 

It works as expected. Redirecting images to another 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 everything no matter what. What I want to see is redirect everything except images. What I'm trying to do in my rules above is to redirect all subdomains of market.mysite.com to market.mysite.com if it is not market.mysite.com, and if it is not an image. In other words:

 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 a wildcard subdomain, so all my sub-domains of the market will use the same directory. And then it answers all requests with a single php file. index.php

Thanks,

+4
source share
1 answer

Replace the existing code as follows:

 Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteCond %{HTTP_HOST} ^[^.]+\.market\.mysite\.com$ [NC] RewriteCond %{THE_REQUEST} !^[AZ]{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] 

Testing in another browser or flushing the existing browser cache.

+4
source

Source: https://habr.com/ru/post/1497952/


All Articles