Here is one of the things I have done for my high performance (see my biography).
I give you an advanced RewriteRule, I am sure that you will have enough material to complete:
Creating static domains:
static.example1.com static.example2.com static.example3.com
Where all your images will be.
From now on, no more than:
www.example1.com/images/www.example1.com/picture.jpg www.example2.com/images/www.example2.com/picture.jpg www.example3.com/images/www.example3.com/picture.jpg
but
static.example1.com/picture.jpg static.example2.com/picture.jpg static.example3.com/picture.jpg
Good urls? Now create vhost with all your static files:
<VirtualHost *> ServerName static.example1.com ServerAlias static.example2.com static.example3.com </VirtualHost>
Set the root of the document to the database without the name vhost, so in your case:
DocumentRoot "/public_html/images"
And add this RewriteRule
RewriteCond %{HTTP_HOST} ^static\.([a-zA-Z0-9\-]+)\.com$ # Change the path, and add the request: RewriteRule (.*) %{DOCUMENT_ROOT}/static.%1.com$1 [QSA,L]
So, all:
<VirtualHost *> ServerName static.example1.com ServerAlias static.example2.com static.example3.com RewriteCond %{HTTP_HOST} ^static\.([a-zA-Z0-9\-]+)\.com$
It’s good that it doesn’t answer exactly your question, so here is a short answer, but I don’t like it because it won’t help you do a very (very) good job:
RewriteCond %{HTTP_HOST} ^www\.(example1|example2|example3)\.com$ # Change the path: RewriteRule (.*)(\.(css|js|txt|htc|pdf|jpg|jpeg|gif|png|ico))$ %{DOCUMENT_ROOT}/www.%1.com$1$2 [QSA,L]
And if this is not enough:
Two tips:
If you are hosting in a non- hosted environment (= if your own server can change virtual hosts, and not just .htaccess ), try using the RewriteLog directive: this will help you identify such problems:
# Trace: # (!) file gets big quickly, remove in prod environments: RewriteLog "/web/logs/mywebsite.rewrite.log" RewriteLogLevel 9 RewriteEngine On
My favorite regexp checker tool:
http://www.quanetic.com/Regex (don't forget to select ereg (POSIX) instead of preg (PCRE)!)