Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've lifted most of this from Wordpress, so any path on the domain like say /search or /list is directed to /index.php. Fine that works.

However, it should not do that if the file being requested exists in the document root. So if I request /exists.php it should run that script. Instead it's ignoring files on the filesystem and continues to serve index.php.

<VirtualHost *:80>

  DocumentRoot /home/sites/dev
  ServerName dev.vbox

  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule . /index.php

  ErrorLog /var/log/apache2/dev.error.log

</VirtualHost>

I've gone through the mod_rewrite documentation and various Google search results but I don't see anything wrong with my rewrite conditions. If the requested filename is a file or a directory, do not redirect to /index.php.

I've cd to the doc root and listed the contents of that directory, the file I'm requesting exists. My apache access log has entries for /exists.php.

The document root is a mounted directory that lives on the my Mac and the VM serving the request is Ubuntu install.

share|improve this question

2 Answers 2

Try %{LA-U:REQUEST_FILENAME} instead of %{REQUEST_FILENAME}. The LA-U prefix is needed before the request is mapped to the filesystem.

Edit:

Didn't catch it in my first pass, you also need to change the first argument to RewriteRule like so:

<VirtualHost *:80>
    DocumentRoot /home/sites/dev
    ServerName dev.vbox

    RewriteEngine On
    RewriteCond %{LA-U:REQUEST_FILENAME} !-d
    RewriteCond %{LA-U:REQUEST_FILENAME} !-f
    RewriteRule .* /index.php

    ErrorLog /var/log/apache2/dev.error.log
</VirtualHost>
share|improve this answer
1  
I changed both my rewrite conditions to %{LA-U:REQUEST_FILENAME}, it basically acts as if mod_rewrite is off, serving exists.php but not mapping /search to index.php. Going to / serves /index.php as you'd expect. –  Greg K Dec 5 '10 at 10:11
    
Add this sorted it so exists.php is served when requested but /search is still serviced by index.php: RewriteCond %{REQUEST_FILENAME} !^.*\.(css|js|php|html)$ [nocase] –  Greg K Dec 5 '10 at 11:17
    
Didn't catch it in the first pass, added an edit about the RewriteRule. –  mark Dec 5 '10 at 20:38
    
I just tested this and /search does not work, it's doesn't redirect to index.php - I can access /exists.php though. –  Greg K Dec 9 '10 at 11:54
up vote 0 down vote accepted

I ended up adding another rewrite condition, so my working Virtualhost looked like this:

<VirtualHost *:80>

  DocumentRoot /var/www/public_html
  ServerName domain.com

  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !^.*\.(php)$ [nocase]
  RewriteRule . /index.php

</VirtualHost>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.