L
L
leoismyname2014-03-04 09:37:02
Apache HTTP Server
leoismyname, 2014-03-04 09:37:02

Working with subdomains in Apache. How to optimize VirtualHost?

There is a terrible idea to do this:

listing >
  site.ru
    www/
      0/www/
      current > 0/
    work/
      0/www/
      1/www/
      current > 0/

site.ru > site.ru/www/current/www/
work.site.ru > site.ru/work/current/www/
current.work.site.ru > site.ru/work/current/www/
1.work.site.ru > site.ru/work/1/www/
0.1.work.site.ru > site.ru/work/1/0/

I thought that such a structure is easy to maintain, I even wrote a script for this. Unfortunately, there is no way to use nginx, only Apache, with which I am not very familiar, trying to find the answer to the question - "how to make it easier?" were not successful.
Here's what I settled on, to my shame and disgrace (non-key parameters skipped):
<VirtualHost 1.2.3.4:56 >
  ServerName site.ru
  ServerAlias www.site.ru
  VirtualDocumentRoot /var/www/user/data/www/site.ru/www/current/www/
</VirtualHost>
 
<VirtualHost 1.2.3.4:56 >
  ServerName www.0.www.site.ru
  ServerAlias *.*.*.site.ru 
  VirtualDocumentRoot /var/www/user/data/www/site.ru/%-3/%-4/%-5/
</VirtualHost>
 
<VirtualHost 1.2.3.4:56 >
  ServerName 0.www.site.ru
  ServerAlias *.*.site.ru
  VirtualDocumentRoot /var/www/user/data/www/site.ru/%-3/%-4/www/
</VirtualHost>
 
<VirtualHost 1.2.3.4:56 >
  ServerName test.site.ru
  ServerAlias *.site.ru
  VirtualDocumentRoot /var/www/user/data/www/site.ru/%-3/current/www/
</VirtualHost>

There must be a better solution, are there any options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FacedSID, 2014-04-15
@FacedSID

You can try to look towards ModRewrite. Create one VritualHost:

<VirtualHost 1.2.3.4:56 >
  ServerName site.ru
  ServerAlias *.site.ru
  DocumentRoot /var/www/user/data/www/site.ru/router/
</VirtualHost>

Site.ru/router/ contains .htaccess with prescribed redirection rules. How complex the structure of this file can turn out, I cannot say, but it should work anyway.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question