Rewrite Problem solved

Sometimes you just have to read the documentation to find out what you did wrong! The ZendFramework uses a concept which pushes all requests through the index.php page in the root directory, this in turn calls the Controller functions to determine how the request is to be handled (yes I made that a lot simpler than it is, but having read through the documentation a number of times it still blows my mind and I cant simplify enough to make sense, so read the docs!). For this to work you have to set up a Rewrite rule which will turn all requests to the URL into a request for /index.php. After reviewing my configs for a previous setup I thought I had it worked out, unfortunately it took a bit more reading of the Apache manuals to figure out why it didn’t.

I had a couple of problems which caused the Apache server to loop trying to resolve the RewriteRule. Firstly I tried to set up the RewriteRules within a request, this meant the rule was resolved but it became embroiled in a loop because I was trying to push the request to /index.php, which was picked up by the rewriterule again and changed to /index.php which was picked up again…. you can see where I am going with this one! Anyhow the server is configured by default to stop at 10 rewrites so the error didn’t cause to many issues!

Then I managed to somehow misspell RewriteRule as RewiteRule! The request to start the servers seemed to go OK, the messages sent to the menu page said it had all started OK, but a request to the page showed the server was busy! Basically I was getting the initial request through my PHPSERVER instance but the proxy request to the PASE Apache server bounced! (it was not started!) After a bit of trawling through the logs and message queues I finally found a spool file in QPRINT which showed the error! This should have been easier to find, but the implementation forced upon Zend by IBM and probably a lack of i5 knowledge means you have to trawl through a number of places to find out whats going on!

Now I have a working ZendFramework environment. The requests work as they should and I can now move forward.

Here are the changes I made along with some explanations where appropriate.

We did not have to change the PHPSERVER configs at all, the Framework is only used at the PHP level so we could simply change the Apache config file in /usr/local/Zend/Apache2/conf/httpd.conf.

   DirectoryIndex index.php index.html
   DocumentRoot /www/apps/spmgr/htdocs
   ServerName app.spmgr.local
      Options Indexes FollowSymLinks
      Order Deny,Allow
      Allow From All
   RewriteEngine on
   RewriteRule !.(js|ico|gif|jpg|png|css)$ /index.php
   RewriteLog "/www/apps/spmgr/tmp/rewrite.log"
   RewriteLogLevel 2

Couple of things to remember about the RewriteRule, the settings can be done at the server or VirtualHost level in most cases. VirtualHost level is great for us. If you need it at the directory level then use the .htaccess file in the directory to set up rewrite rules. The use of .htaccess can be a drain on your servers performance so use with care. We commented out the use of the .htaccess files as we don't have any need for them in our environment. Here is where we removed the .htaccess configurations in the PASE Apache config.

Set Allow Overrides to None
AllowOverride None
commented out the AccessFilename config we don't want the server looking for the file
# AccessFileName .htaccess
commented out the .ht filename authorities for web robots, we didn't have to do this.
#    Order allow,deny
#    Deny from all

The directory structure we have used for the test so far is what the documentation suggest we use, this allows the MVC to function correctly, however there are a number of ways which you can amend the structure to meet your own individual needs. If you need more information about this and the Framework implementation then checkout the documentation

/htdocs - This is the document root for the web server so all of the application data is not available directly to the public especially the web robots.

If you wish to build the same test we did you can use the Quicksetup guide which is available at the beginning of documents listed above. Now we need to add some of our own content to the structure to build out our own project.

Hope this is interesting, we will continue to post on our progress as we go!


One thought on “Rewrite Problem solved”

  1. Once you have finished testing your setup and know the server is correctly rewriting your requests you may want to set the logging of rewrite requests to off. This can be done by setting the RewriteLogLevel to 0.

    Sorry meant to add this as I wrote the post!


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.