Search code examples
wordpressvirtualhostredhat

Remove index.php in Wordpress subfolders when using virtual hosts


I have looked everywhere to find a solution to this problem, but nothing i have tried has worked. When having the permalink settings to /index.php/%postname%/ it works fine, but when i remove the index.php part i only get a 404 and this in the log:

[Tue Aug 13 05:05:46 2013] [error] [client 202.58.198.84] File does not exist: /var/www/html/domain1/postname, referer:.....

I have a Red Hat webserver running Apache with two Wordpress sites through with virtual hosts. The virtual hosts look like this.

<VirtualHost *:80>
  # General
  ServerAdmin info@domain1.com
  DocumentRoot /var/www/html/domain1
  ServerName domain1.com
  ServerAlias www.domain1.com

  # Logging
  ErrorLog logs/domain1-error_log
  CustomLog logs/domain1-access_log common
</VirtualHost>

and

<VirtualHost *:80>
  # General
  ServerAdmin info@domain2.com
  DocumentRoot /var/www/html/domain2
  ServerName domain2.com
  ServerAlias www.domain2.com

  # Logging
  ErrorLog logs/domain2-error_log
  CustomLog logs/domain2-access_log common
</VirtualHost>

The .htaccess file in the sub folders looks like this after changing the permalink in frontend settings.

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

I also tried to change

RewriteBase /

to

RewriteBase /subfolder

without any luck.

This is not a huge problem but it bugs me a lot! I would appreciate if someone had a solution to this.


Solution

  • Make sure that:

    • your wordpress permalink settings is set to /%postname%
    • the .htaccess file is placed inside /var/www/html/domain1 (same for domain2)
    • you specify some rules for the domain1/2 directory like this (add this piece of code right before the </virtualhost> tag inside your configuration file):

      <Directory /var/www/html/domain1>
              Options FollowSymLinks MultiViews
              AllowOverride All
              Order allow,deny
              allow from all
      </Directory>