Why is my LAST rule [L] not working in apache?

感情迁移 提交于 2019-12-24 08:28:30

问题


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:


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]



回答2:


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



来源:https://stackoverflow.com/questions/1784743/why-is-my-last-rule-l-not-working-in-apache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!