简体   繁体   中英

Create a dynamic vhost in apache

All my vhost are the same way and I dont want to create for every project a new one so I thought there is maybe a way to match the project_name environment based on the domain which call the webserver.

My current Vhost:

<VirtualHost *:80>
    DocumentRoot "/Users/l91/Development/<project_name>/web"
    ServerName <project_name>.<environment>

    <Directory "/Users/l91/Development/<project_name>/web">
        Options Indexes FollowSymlinks
        SetEnv SYMFONY_ENV <environment>
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

It sounds more like you're looking for aliases or rewrites, rather than a virtual host. You can likely use rewrite rules to find them dynamically.

Did get it to work with this configuration:

NameVirtualHost *:80

<Directory "/Users/l91/Development/Websites">
    Options Indexes FollowSymlinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

UseCanonicalName Off
VirtualDocumentRoot /Users/l91/Development/Websites/%0/web

SetEnvIf X-SYMFONY_ENV "^prod$" SYMFONY_ENV=prod
SetEnvIf X-SYMFONY_ENV "^stage$" SYMFONY_ENV=stage
SetEnvIf SYMFONY_ENV "^$" SYMFONY_ENV=dev

and use of the following plugin to change ENVs by setting a header: https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj

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