Created
March 28, 2012 21:19
-
-
Save logsol/2230673 to your computer and use it in GitHub Desktop.
Apache - automatically route all subdomains to their related directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=========================================================================== | |
APACHE | |
How to get "anysubdomain.mydomain.com" automatically routed to a directory? | |
=========================================================================== | |
1.) enable mod_vhost_alias (create symlink in mods-enabled) | |
2.) create the following vhost configuration file /etc/apache/sites-available/subdomains | |
<VirtualHost *:80> | |
ServerName mydomain.com | |
ServerAlias *.mydomain.com | |
VirtualDocumentRoot /path/to/webspace/%1/public | |
SetEnv APPLICATION_ENV dev | |
</VirtualHost> | |
3.) to enable, create symlinks for subdomains in /sites-enabled | |
4.) restart apache | |
Pro tipp no. 1: | |
I set VirtualDocumentRoot to /var/www/ where I only have a load of soft links to my actual projects. | |
Pro tipp no. 2: | |
%1 will stands for the name of the subdomain only meaning, if someone opens sub.mydomain.com, apache will look for /path/to/webspace/sub/public. if you use %0 the whole domain name is used /path/to/webspace/sub.mydomain.com/public |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment