Here's my goal : I have 9 websites running (names changed of course) :
- we.com
- we.fr
- doo.com
- doo.fr
- fpp.com
- ke.com
- wpp.com
- wgg.com
- t-y-u.fr
I wanted for each website :
- a directory to put a rotating log file. Done.
- update awstats for each on a 24 h basis and put the results in a separate directory :
- /web/awstats/we_com/ - /web/awstats/we_fr/ - /web/awstats/doo_com/ - /web/awstats/doo_fr/ - /web/awstats/fpp_com/ - /web/awstats/ke_com/ - /web/awstats/wpp_com/ - /web/awstats/wgg_com/ - /web/awstats/t_y_u_fr/
- make only one virtual host for a generic stats website and given a name, re-direct to the good statistics website. If you type one of those URLs the base path for the site should be changed accordingly :
1. http://stats.we.com/ change the base directory to /web/we_com 2. http://stats.we.fr/ change the base directory to /web/we_fr 3. http://stats.doo.com/ change the base directory to /web/doo_com 4. http://stats.doo.fr/ change the base directory to /web/doo_fr 5. http://stats.fpp.com/ change the base directory to /web/fpp_com 6. http://stats.ke.com/ change the base directory to /web/ke_com 7. http://stats.wpp.com/ change the base directory to /web/wpp_com 8. http://stats.wgg.com/ change the base directory to /web/wgg_com 9. http://stats.t-y-u.fr/ change the base directory to /web/t_y_u_fr
I've done it but it's sooooooo long : for each site here are the rules :
########################################### # site we.com RewriteCond %{HTTP_HOST} ^stats\.we\.com RewriteRule ^/$ /we/awstats.we.xml [QSA,L] # change other dirs to the base dir : RewriteCond %{HTTP_HOST} ^stats\.we\.com RewriteCond %{HTTP_HOST} ^stats\.we\.com RewriteRule ^/(.*) /wheeg/$1 [QSA,L]
if you have a good way of optimizing it i'd like to see it (remember there's one site with "-" and they have to be changed to "_") !
First rule of optimization: don't. Second rule of optimization (advanced use only): don't yet.
If it is working already, and is not causing any performance or maintenance issues, I would leave well alone.
Can't you use - instead of _ for t-y-u.fr ? because you could use a unique mass vhost configuration like this one for all your domains :
Check http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html for more documentation. May be by adding a rewrite rule you could change - by _ in the DocumentRoot path. This need some tries.
But generaly, tree are done like this :
And with one vhost by domaine using VirtualDocumentRoot you can do what you want.
Also bear in mind, putting mod_rewrite rules in central apache config files is more efficient that using .htaccess files, as they .htaccess file have to be re-read every time the site is requested.