Trouble configuring virtual host to allow standard wordpress mod_rewrite for permalinks

Rooster asked:

I’m having a little trouble getting the standard mod_rewrite that wordpress generates in my directorys .htaccess file to work correctly. The server I’m using has a virtual host set up on it by default, and I’m a little inexperienced configuring them. Ive reached a point where my head hurts from banging it against the wall so any help is appreciated.

so hypothetically, we can say my domain is:

http://domain.com

and I have my wordpress in

http://domain.com/wordpress

so for my pretty links, the .htaccess file that is in domain.com/wordpress reads:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>

and my virtual host config file located at etc/apache2/sites-available/domain.com.conf:

<VirtualHost *:80>
  ServerName app01
  ServerAlias domain.com www.domain.com 
  DocumentRoot /var/www/vhosts/application/

  <Directory /var/www/vhosts/application>
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory> 

  <Directory />
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>

  <Location /server-status>
    SetHandler server-status

    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
  </Location>

  LogLevel info
  ErrorLog /var/log/apache2/domain.com-error.log
  CustomLog /var/log/apache2/domain.com-access.log combined

  RewriteEngine On
  RewriteLog /var/log/apache2/domain.com-rewrite.log
  RewriteLogLevel 0
</VirtualHost>

So when this is working,

a page save as testpage would be reachable at :

http://domain.com/wordpress/testpage

Ive been struggling with this for a while so any help is appreciated!

Cheers!

My answer:


You’re missing a line in your .htaccess.

Start with the standard default .htaccess provided by WordPress, and I think you will find your problems go away.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.