0

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.

  • The question really is how to take as a parameter the first part after the domain: http://www.domain.com/param1. Any ideas? – Onesiphorus Jun 24 '14 at 09:03

1 Answers1

0

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.

Go0se
  • 98
  • 1
  • 8
  • Thanks for your reply. Although that works for the domain name (mapping .com to folder ) the subfolder of the URL is still a problem, as ServerAlias does not take anything after the ".com" into account. I need .com// to map to /home//. I don't quite understand the purpose of "000-deafult.conf"? Thanks. – Onesiphorus May 05 '14 at 13:41
  • The server does not take anything after the .com into account, because it is passed as is (Like a directory structure) to the 'folder'. Therefore // should direct to the folder // in the public_html folder – Go0se May 06 '14 at 05:18
  • But I need the document root to be /home//, because that folder contains the index.php entry point for the website. With your solution, e.g., domain.com/site/param would try to find a file in "site/param", wouldn't it? That wouldn't work as there's no "param" folder. – Onesiphorus May 06 '14 at 08:37
  • Yes you are correct. May I suggest you look at the following URL and research the URL part of your question from there? : http://stackoverflow.com/questions/658978/mod-rewrite-convert-folders-in-url-into-query-parameters – Go0se May 08 '14 at 09:37
  • I'm afraid that's not what I need. I've had it configured like that so far, using the domain part as the key to redirect, but what I need is the subfolder part to be taken as well. Passing it as part of the query is not what I want either. It should only be used to map the directory root, and act as a normal root path with the URL being whatever is after domain.com/folder. Thanks anyway for your help. – Onesiphorus May 22 '14 at 07:17