Skip to content

Instantly share code, notes, and snippets.

@nicolasramy
Created July 30, 2012 12:43
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nicolasramy/3206657 to your computer and use it in GitHub Desktop.
Save nicolasramy/3206657 to your computer and use it in GitHub Desktop.
Simple Apache2 Virtual Host for WordPress
<VirtualHost *:80>
ServerAdmin nicolas.ramy@hostname.com
ServerName wordpress.local
# Indexes + Directory Root.
DirectoryIndex index.php index.html
DocumentRoot /var/www/workspace/wordpress/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond $1 ^(index\.php)?$ [OR]
RewriteCond $1 \.(gif|jpg|png|ico|css|js)$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [S=1]
RewriteRule . /index.php [L]
</IfModule>
# END wordpress
Options FollowSymLinks
Order allow,deny
Allow from all
</VirtualHost>
@mjhumphrey4
Copy link

Nice!

@endersaka
Copy link

Order and Allow are valid only in directory and .htaccess context.

This configuration if checked (httpd.exe -t or apachectl configtest) you will see this error:

AH00526: Syntax error on line XX of <path_to>/httpd-vhosts.conf:
order not allowed in <VirtualHost> context

@ben-iP
Copy link

ben-iP commented Aug 17, 2022

This could help:

<VirtualHost *:80>
	ServerAdmin nicolas.ramy@hostname.com
	ServerName  wordpress.local
 
	# Indexes + Directory Root.
	DirectoryIndex index.php index.html
	DocumentRoot /var/www/workspace/wordpress/
 
	<Directory "/var/www/workspace/wordpress">
          AllowOverride All
          Options FollowSymLinks
          Order allow,deny
          Allow from all
        </Directory>

	# BEGIN WordPress
	<IfModule mod_rewrite.c>
		RewriteEngine On
		RewriteRule ^index\.php$ - [L]
		RewriteCond $1 ^(index\.php)?$ [OR]
		RewriteCond $1 \.(gif|jpg|png|ico|css|js)$ [NC,OR]
		RewriteCond %{REQUEST_FILENAME} -f [OR]
		RewriteCond %{REQUEST_FILENAME} -d
		RewriteRule ^(.*)$ - [S=1]
		RewriteRule . /index.php [L]
	</IfModule>
	# END wordpress
        
        LogLevel warn
        CustomLog /var/log/apache2/wordpress-access.log combined
        ErrorLog /var/log/apache2/wordpress-error.log
</VirtualHost>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment