IIRF Rewrite Rules for Zend Framework?

Topics: Developer Forum, Project Management Forum, User Forum
Jan 22, 2009 at 9:37 PM
Hello all,

I require the 'definitive' rewrite rules for use with the Zend Framework. More info on the framework can be found here: http://framework.zend.com

The framework uses the MVC design pattern with all requests being routed through a single entry point of 'index.php'.

Using .htaccess this is achieved with the following rules:
RewriteEngine on
RewriteBase /
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
I am trying to re-write the above for use with IIRF.

Currently I have the following:

RewriteRule ^/(.*(js|ico|gif|jpg|png|flv|swf|css))$ /$1 [L,I,U]
RewriteRule ^(.*)$ /index.php [L,I,U]
This successfully routes requests to index.php. The problem I then faced was collecting any query strings that may be in the URL.

Changing the second line of the above to the following works but not satisfactorily:
RewriteRule ^(.*)$ /index.php$1 [L,I,U]
The above will pass query strings (correctly) in the form:

http://www.example.com/search?query=test

Unfortunately requests such as the following are not routed correctly:

http://www.example.com/js/FCKeditor/fckeditor.js?_=1232639553453

The above gets routed to index.php when it should not! It is a JavaScript file but the query string parameters confuse the routing...

Note that the rules shown on the Zend Framework Wiki pages are poor and definitely incomplete:

http://framework.zend.com/wiki/display/ZFDEV/Configuring+Your+URL+Rewriter

Can anybody help write the definitive rewrite rules for the Zend Framework once and for all? I believe I am definitely not the only one who requires these rules so please help us out!

Thanks,

David






Feb 24, 2009 at 3:59 PM
True, you're not the only one. My ZF application is not at the web root, but just take out the folder references below. I've had some success with these rules:

RewriteRule ^/zendproject/(.*(\.js|\.swf)(\?.+))$ - [L,I]
RewriteRule ^/zendproject/(.*(\.js|\.ico|\.gif|\.jpg|\.png|\.css|\.html|\.htm|\.swf|\.flv))$ /zendproject/$1 [L,I]
RewriteRule ^/zendproject/(.*)$ /zendproject/index.php [L,I]

I added the 1st one above the "standard" Zend Framework IIRF rules after having a similar problem to yours. I wanted to tack a phony query string on to my SWF filename in swfobject dynamic include, to keep it from caching during the development cycle. (myapp.swf?rndl=<?php echo floor(microtime(true)); ?>)

In plain English, I believe these rules are equivalent to:
- If a *.js or *.swf file is requested from zendproject and appears to have a querystring - question mark afterward, do not rewrite anything.
- If a file is requested from zendproject with any one of these extensions, rewrite it by appending the whole matching path and filename to /zendproject/
- Rewrite all other request on zendproject to index.php

I would have liked that 1st rule to be a little better but it works for now in my situation.

If this leads you to any improvements please post.