views:

131

answers:

2

Background, I'm running a Zend Framework application. Trying to squeeze the most performance out of it as possible. So I'm trying to move the rules out of .htaccess exactly to the letter per this blog post by the author of a Zend Framework book: http://www.armando.ws/2009/03/how-to-run-zend-framework-with-no-htaccess-file/

So basically, in httpd.conf, I'm adding an include to conf/extra/httpd-zf.conf which contains the same thing that was in my .htaccess file and working perfectly.

Here's the pertinent code that doesn't function right in httpd-zf.conf:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L,NC]
RewriteRule ^.*$ /index.php [NC,L]

Controllers work fine. The index.php is seen. But static files don't work. It errors out saying that it isn't a valid controller, so clearly it's being run through index.php.

It's almost as if after running:

RewriteRule ^.*$ - [L,NC]

it keeps right on going. And in point of fact, Removing this line:

RewriteRule ^.*$ /index.php [NC,L]

fixes the static files, but of course breaks the rest of it.

So basically the LAST rule is not working it seems.

Any ideas on getting this to work correctly?

Thank you.

UPDATE

After turning on logging (I had to hike it up to Loglevel 9), it turned out that even though removing RewriteRule ^.*$ /index.php [NC,L] allowed static files to resolve, it was NOT matching on condition RewriteCond %{REQUEST_FILENAME} -s no matter what...it just did "pass through" anyway which allowed the file to show...

so clearly, the fact that .htaccess was on the correct path made it work where the httpd-zf.conf has the wrong path.... There must be a spot somewhere that I can tell httpd-zf.conf what my docroot path is...

+1  A: 

I don't believe the conditions are associated with the second rule. I suggest turning on rewrite debugging: RewriteLog "/myfolder/mylogfile.log" and RewriteLogLevel 3

Try:

RewriteCond %{REQUEST_FILENAME} !-s 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [NC,L]
segy
Great idea on the debugging. But not sure the conditions really should be associated with the second rule though. Zend Framework wants all static files to be run normally, then if there is no static file, to funnel the rest through index.php which will map to a controller...
joedevon
Just edited the original answer, it may more closely match the issue now. I've switched to negative conditions, which should remove the need for two rules. Cheers.
segy
Thanks...that didn't work either though. See my updated question... BTW, do you know how I can add a path to httpd-zf.conf? It seems the path is the problem...
joedevon
A: 

Found the solution!!

Here's the code that works:

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -s [OR]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -l [OR]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d

This wiki post explains why it wasn't working: http://wiki.apache.org/httpd/RewriteContext

joedevon