Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Virtual host file for port 80 that redirects 'www' alias to main domain, uses 'cronolog' to rotate error and access logs, redirects non-whitelisted hosts to main site, allows access to itself via URL-based cron jobs, and prompts users of permitted group for username and password via basic authentication. Also includes rewrite map to redirect dom…
<VirtualHost *:80>
RewriteEngine On
RewriteMap redirect_map_master txt:vhosts.d/includes/redirect_map_master
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteCond ${redirect_map_master:%2|} ^(.+)$ [NC]
RewriteRule ^/$ http://%1 [L,R=301]
<VirtualHost *:80>
DocumentRoot /var/www/domains/
ErrorLog "|/usr/local/sbin/cronolog -l /var/www/domains/ /var/www/domains/"
CustomLog "|/usr/local/sbin/cronolog -l /var/www/domains/ /var/www/domains/" combined
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\ [NC]
RewriteRule ^/(.*)$$1 [R=301,L]
RewriteCond %{REMOTE_HOST} !^111\.111\.111\.111
RewriteCond %{REMOTE_HOST} !^222\.222\.222
RewriteRule / [R=302,L]
<Directory />
AuthType Basic
AuthName "Restricted Area"
AuthBasicProvider file
AuthUserFile /var/www/htpasswd/users
AuthGroupFile /var/www/htpasswd/groups
Require group groupname1
Order Allow,Deny
Allow from
Satisfy any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment