简体   繁体   中英

How to get default host work with mod_vhost_alias without mod_rewrite?

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>

认为您必须先加载所有〜normal〜虚拟主机,然后再加载mod_vhost_alias

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM