Apache dynamic subfolders

445 views Asked by At

I need to setup Apache so it deals with 2 different disk locations and maps different sites dinamically based on the subfolder on the URLs:

http://localhost1/site1.com/
http://localhost1/site2.com/
http://localhost2/site3.com/
...

That will map respectively to:

C:\folderOne\site1.com\public_html
C:\folderOne\site2.com\public_html
C:\folderTwo\site3.com\public_html
...

I've found examples that use mod_vhost_alias, mod_alias and mod_rewrite for different things, but have not been able to implement what I need.

Thanks.

1

There are 1 answers

5
Go0se On

To redirect the sites dynamically, you could try the following:

In Apache's sites-available folder, you should have a file called 000-deafult.conf, or something similar. You need to edit this file to do the redirecting.

However, the only way you can redirect to another sub folder dynamically is if your domain have something that indicates the subfolder to use, like to sort the domains according to TLD's.

Therefore I would suggest something like:

 UseCanonicalName Off

 <VirtualHost *:80>
  ServerName vhosts.fqdn
  ServerAlias www.*.com
  VirtualDocumentRoot /c/com/%2/public_html
 </VirtualHost>

 <VirtualHost *:80>
  ServerName vhosts.fqdn
  ServerAlias *.com
  VirtualDocumentRoot /c/com/%1/public_html
 </VirtualHost>

<VirtualHost *:80>
  ServerName vhosts.fqdn
  ServerAlias www.*.net
  VirtualDocumentRoot /c/net/%2/public_html
 </VirtualHost>

 <VirtualHost *:80>
  ServerName vhosts.fqdn
  ServerAlias *.net
  VirtualDocumentRoot /c/net/%1/public_html
 </VirtualHost>

And so forth.

Hope this answers your question.