Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created March 12, 2016 15:48
Show Gist options
  • Save ehzawad/825dca22cd2a731708a3 to your computer and use it in GitHub Desktop.
Save ehzawad/825dca22cd2a731708a3 to your computer and use it in GitHub Desktop.
# allow all overrides and options
<Directory /home/jharvard/vhosts>
AllowOverride All
Options All
Require all granted
</Directory>
# VirtualHost will override apache2.conf defaults
<VirtualHost *:80>
# get the server name from the Host: header
UseCanonicalName Off
# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog /home/jharvard/logs/apache2/access_log vcommon
ErrorLog /home/jharvard/logs/apache2/error_log
RewriteEngine On
# a ServerName derived from a Host: header may be any case at all
RewriteMap lowercase int:tolower
# VirtualDocumentRoot /home/jharvard/vhosts/%0/public
# http://httpd.apache.org/docs/2.2/vhosts/mass.html#simple.rewrite
RewriteCond %{REQUEST_URI} !^/(icons|phpmyadmin)(|/.*)$
RewriteCond /home/jharvard/vhosts/${lowercase:%{SERVER_NAME}} -d [OR]
RewriteCond /home/jharvard/vhosts/${lowercase:%{SERVER_NAME}} -l
RewriteRule ^/(.*)$ /home/jharvard/vhosts/${lowercase:%{SERVER_NAME}}/public/$1 [L]
# DocumentRoot /home/jharvard/vhosts/localhost/public
RewriteCond %{REQUEST_URI} !^/(icons|phpmyadmin)(|/.*)$
RewriteCond /home/jharvard/vhosts/${lowercase:%{SERVER_NAME}} !-d
RewriteCond /home/jharvard/vhosts/${lowercase:%{SERVER_NAME}} !-l
RewriteRule ^/(.*)$ /home/jharvard/vhosts/localhost/public/$1 [L]
# not production
SetEnv APPLICATION_ENV dev
</VirtualHost>
# avoid favicon.ico errors in logs
Alias /favicon.ico /var/www/icons/favicon.ico
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment