Can't figure out why RewriteCond with !-f doesn't work
Posted: Wed Apr 21, 2010 7:21 pm
I'm trying to get a FastCGI application up and running where the CGI itself is outside of the web root.
I can get the FastCGI app to load just fine such that *anything* in the URL is passed along to the app. However, I want to exclude static resources so I tried adding a RewriteCond using !-f on the REQUEST_FILENAME. It just seems to ignore it entirely and the FastCGI app ends up taking the request instead of Apache serving up the file.
I have placed a text file in the static directory, named "hello.txt" with just the word "Boo" in it. I should be able to access /hello.txt and see that text file, however the -f rule isn't taking care of it.
So out of desperation (and for the sake of my own sanity) I wrote a one-off rule for paths starting with "/hello". Low and behold, this correctly serves up the text file and all other URLs route through to my FastCGI application. Which begs the question, why doesn't the previous rule work?
I'm at a loss
I've set so many RewriteRules up like this over the years (granted, not for a FastCGI app) and cannot see what I'm missing.
I can get the FastCGI app to load just fine such that *anything* in the URL is passed along to the app. However, I want to exclude static resources so I tried adding a RewriteCond using !-f on the REQUEST_FILENAME. It just seems to ignore it entirely and the FastCGI app ends up taking the request instead of Apache serving up the file.
Code: Select all
AppClass /Sites/CioccolataTest.webapp/Contents/MacOS/CioccolataTest -port 5065
FastCgiExternalServer /Sites/CioccolataTest.webapp/Contents/MacOS/CioccolataTest.fcgi -host 127.0.0.1:5065
<VirtualHost *:80>
ServerName cioccolata-test.webdev
DocumentRoot "/Sites/CioccolataTest.webapp/Contents/Resources/static"
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ /Sites/CioccolataTest.webapp/Contents/MacOS/CioccolataTest.fcgi/$1 [QSA,L]
</VirtualHost>So out of desperation (and for the sake of my own sanity) I wrote a one-off rule for paths starting with "/hello". Low and behold, this correctly serves up the text file and all other URLs route through to my FastCGI application. Which begs the question, why doesn't the previous rule work?
Code: Select all
AppClass /Sites/CioccolataTest.webapp/Contents/MacOS/CioccolataTest -port 5065
FastCgiExternalServer /Sites/CioccolataTest.webapp/Contents/MacOS/CioccolataTest.fcgi -host 127.0.0.1:5065
<VirtualHost *:80>
ServerName cioccolata-test.webdev
DocumentRoot "/Sites/CioccolataTest.webapp/Contents/Resources/static"
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/hello
RewriteRule ^/(.*)$ /Sites/CioccolataTest.webapp/Contents/MacOS/CioccolataTest.fcgi/$1 [QSA,L]
</VirtualHost>