Xampp Virtualhost:通配符域和子域

时间:2014-04-26 14:59:20

标签: apache xampp wildcard virtualhost wildcard-subdomain

我读完了另一篇文章,但似乎没有人回答我一直有的问题。是否可以使用通配符域的通配符子域(即使它仅用于子域而不是子子域),如:foo.example.local。 我已经有example.local工作,但我无法弄清楚如何让foo.example.local从/ example文件夹中的文件夹/ sub / foo中获取文件。 此时我的配置(httpd-vhost.conf):

NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "C:/xampp/www"
    ServerName localhost
    ServerAlias localhost
</VirtualHost>
<Virtualhost *:80>
VirtualDocumentRoot "C:/xampp/www/%-2"
    ServerName domain.local
    ServerAlias *.local
    <Directory "C:/xampp/www/*">
         Options Indexes FollowSymLinks Includes ExecCGI
         AllowOverride All
         Order allow,deny
         Allow from all
         Require all granted
     </Directory>
</Virtualhost>
<Virtualhost *:80>
    VirtualDocumentRoot "C:/xampp/www/%-2/sub/%-3"
    ServerName sub.domain.local
    ServerAlias *.*.local
    <Directory "C:/xampp/www/*/sub/*">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted     
    </Directory>
</Virtualhost>

目前发生的是foo.example.local只是转到示例文件夹而不是示例/ sub / foo文件夹,这是我想要它做的。

哦,我已经在httpd.conf

中启用了LoadModule vhost_alias_module modules/mod_vhost_alias.so

主机文件包含两行:

  • 127.0.0.1 example.local
  • 127.0.0.1 foo.example.local

2 个答案:

答案 0 :(得分:4)

我想通了,通过通配符添加子域功能我只需要在* .domain.local之前使用第二个星号来*。 *。本地 所以最终结果如下:

<VirtualHost *:80>
    DocumentRoot "C:/xampp/www"
    ServerName localhost
    ServerAlias localhost
</VirtualHost>
<Virtualhost *:80>
    VirtualDocumentRoot "C:/xampp/www/%-2/sub/%-3"
    ServerName sub.domain.local
    ServerAlias *.*.local
    <Directory "C:/xampp/www/*/sub/*">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted     
    </Directory>
</Virtualhost>
<Virtualhost *:80>
    VirtualDocumentRoot "C:/xampp/www/%-2"
    ServerName domain.local
    ServerAlias *.local
    <Directory "C:/xampp/www/*">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
</Virtualhost>

重要的是这个:

VirtualDocumentRoot "C:/xampp/www/%-2/sub/%-3"
ServerName sub.domain.local
ServerAlias *.*.local
<Directory "C:/xampp/www/*/sub/*">

简单的修复使您可以轻松地在与主域相同的文件夹中创建子域。允许您在一个项目文件夹中轻松创建多个域。

答案 1 :(得分:0)

XAMPP 7.3.7(无限* .LOCALHOST)+某些共符号v4域

编辑并激活Apache“虚拟主机别名模块”(取消注释#)

FILE = C:\ xampp \ apache \ conf \ httpd.conf

<?php
$mylink = "limitdatabase.php?Dropdown=" . $_GET[Dropdown] . "&search=" . $search_name . "&wise=" . $_GET[wise];
?>
<a href="<?PHP echo $mylink; ?>">YES</a>

FILE = C:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf

对此进行编辑,可以在Chrome(不是Firefox)上正常工作

LoadModule vhost_alias_module modules/mod_vhost_alias.so

对于HTTPS

FILE = C:\ xampp \ apache \ conf \ extra \ httpd-ssl.conf

#############################
## LOCALHOST
#############################
<VirtualHost *:80>
       UseCanonicalName Off
       DocumentRoot "C:/xampp/htdocs/"
       ServerName localhost
</VirtualHost>


#############################
## SYMFONY VHOSTS (/public)
#############################

<VirtualHost *:80>
       UseCanonicalName Off       
       DocumentRoot "C:/xampp/htdocs/symfonyapi/public/"
       ServerName symfonyapi.localhost

        <Directory C:/xampp/htdocs/symfonyapi/public/>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>       

</VirtualHost>

<VirtualHost *:80>
       UseCanonicalName Off       
       DocumentRoot "C:/xampp/htdocs/symfonyweb/public/"
       ServerName symfonyweb.localhost

        <Directory C:/xampp/htdocs/symfonyweb/public/>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

</VirtualHost>


#############################
## VHOSTS *.LOCALHOST
#############################
<VirtualHost *:80>
       UseCanonicalName Off
       ServerAlias *.localhost
       VirtualDocumentRoot "C:/xampp/htdocs/%1/"
</VirtualHost>

创建域:

<VirtualHost _default_:443>

#   General setup for the virtual host
# DocumentRoot "/xampp/htdocs"
# ServerName www.example.com:443
# ServerAdmin admin@example.com
# ErrorLog "/xampp/apache/logs/error.log"
# TransferLog "/xampp/apache/logs/access.log"

UseCanonicalName Off
ServerAlias *.localhost
ServerAdmin admin@example.com
VirtualDocumentRoot "c:/xampp/htdocs/%1"
ErrorLog "/xampp/apache/logs/%1.error.log"
TransferLog "/xampp/apache/logs/%1.access.log"