0

I recently added a virtual host config to my apache which is using mod_vhost_alias to route requests to domain-like directories. If the directory exists everything works just fine. Now my thought was, when I call a domain which is routed to my apache, but no corrsponding virtual document root exists, the request would be handled by default host. But it isn“t. Is there a solution to do this without using mod_rewrite?

This is my dynamic host config:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerAlias *

    UseCanonicalName Off

    LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    CustomLog /var/log/apache2/dhost_access.log vcommon

    VirtualDocumentRoot /var/www/%0
    VirtualScriptAlias /var/www/%0
</VirtualHost>

And this is my default host:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
dops
  • 1
  • 1

2 Answers2

0

I think you have to load all the ~normal~ vhosts first , then mod_vhost_alias afterwards

0

You can try to add an IF Module in your vhost to check if the folder exists, and if not, redirect to another folder. Try something like this:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ path/to/redirect/to [QSA,L]
</IfModule>
Go0se
  • 98
  • 1
  • 8