The lady that used to own the site I'm running put all of her images into the root directory. Literally thousands of images. The site is huge, and we get tons of traffic from those images so I don't want to just move them without rewriting them to an images folder. Here is what I have already: #RewriteCond %{REQUEST_URI} !/images/.* #RewriteRule ^(.*\.(gif|jpg|jpeg|png|GIF|JPG|JPEG|PNG))$ /images/$1 [QSA,L] Code (markup): The problem is that I believe the above code was also grabbing images from all directories. I would like the rewrite rule to some how apply ONLY to the root directory, and leave all of the images outside of the root directory alone. Is that possible? Thanks!
Assuming the server is running at least Apache 2.2 where Perl 5 syntax is available, you can try excluding anything that has a directory separator in it, RewriteRule ^([^/]+)\.(jpe?g|gif|png)$ /images/$1.$2 [L,NC] Code (markup): You don't need the QSA flag because you're not altering the querystring in your replacement so QSA is automatically implied. If you use the NC (no case) flag you don't have to list the lower and upper case variants of the file extensions. You may want to go through your other directories and explicitly turn RewriteEngine off in them.