0

I'm working with Virtualhosts and a local catch-all domain TLD and I need 3 use-cases to work simultaneously, but so far, I've only been able to get two to work at a time.

I need for three different test domains to be able to access their respective document root.

  1. Case 1: test1.dev --> /path/to/www/SomeFolderName (an override using it's own unique folder name and virtualhost file)

  2. Case 2: *.dev --> /path/to/www/%0 (full url including .dev, so test2.dev points to /path/to/www/test2.dev )

  3. Case 3: *.dev --> /path/to/www/%1 (full url excluding .dev, so test3.dev points to /path/to/www/test3 )

So, I need two wildcard situations for any domain like test2.dev or test3.dev, use VirtualDocumentRoot "/path/www/%0" if it exists or VirtualDocumentRoot "/share/www/%1" if that exists instead.

Right now, either case 2 or case 3 works depending what is loaded first, but not both at the same time. How can I have 1 catch all domain select only the existing document root?

Aaron Butacov
  • 32,415
  • 8
  • 47
  • 61

2 Answers2

0

It's not really supported to have Apache change the document root based on whether or not the directory actually exists. I think you will have better luck standardizing the document roots so that they are all /share/www/testX.dev and creating symbolic links from /share/www/testX.dev to /share/www/testX when necessary. You could even create the symlinks from a custom 404 handler.

Old Pro
  • 24,624
  • 7
  • 58
  • 106
0

You could instead try to use one single document root for all directories and have mod_rewrite check for existence of the folders and/or files (using RewriteCond with -for -d as CondPattern) and rewrite the URLs, so that the correct files are retrieved. This would work with wildcard domains and have quite flexible rules on which folder to use when.

escitalopram
  • 3,750
  • 2
  • 23
  • 24