My software supports multiple domain names all pointed at the same directory on the server (a different database for each of course). So these domains…
www.example1.com
www.example2.com
www.example3.com
…all point to…
/public_html/
In the image directory…
/public_html/images/
I have directories that exactly match the host names for each website:
/public_html/images/www.example1.com/
/public_html/images/www.example2.com/
/public_html/images/www.example3.com/
I’m trying to get Apache to rewrite requests so that if you view the image directly and look at the address bar you only see the host name once.
So a request for…
http://www.example1.com/images/book.png
…is fetched by Apache at…
/public_html/images/www.example1.com/book.png
One of the things I’ve tried and have had success with in different circumstances is the following though it doesn’t work in this situation:
RewriteRule ^[^/]*/images(.+) images/%{HTTP_HOST}/$1
Try adding the following to the
.htaccessfile in the root directory of your site (public_html)Your rule
did not work because you have a leading
/beforeimages. In .htaccess the leading/is removed, so the rule would never match.