The leading edge of scripting languages and Oracle Database brought to you by the Data Access Development team

  • php
    September 3, 2010

Zend Framework .htacess and Multiple Controllers

Christopher Jones
Senior Principal Product Manager

Here is a Zend Framework configuration tip that took me too long to work out. I know other people have commented on it before me but often installation instructions don't mention the error or associate it with the required fix. I'm filing this under the "posting it so I can find it when I need it again" category.

I tend to do all my PHP work in $HOME/public_html and configure all my various Apache versions similar to:

UserDir public_html
<Directory "/home/*/public_html">
. . .

This way it doesn't matter what Apache I start (or destroy). All my working PHP files remain accessible.

I've been using NetBeans with Frameworks recently. I had no problem when doing a single controller example in Zend Framework, so I knew everything was installed OK and mod_rewrite was "working" fine. But I would click a URL that should be routed to a second controller and see an error like:

The requested URL /home/cjones/public_html/MyProject/public/index.php
was not found on this server.

The solution is to update the .htaccess file. In the Netbeans Projects pane navigate to Source Files > public > .htaccess or on disk edit /home/cjones/public_html/MyProject/public/.htacces and insert a new RewriteBase line so it reads:

RewriteEngine On
RewriteBase /~cjones/MyProject/public
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.