Zend Framework .htacess and Multiple Controllers

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">
 . . . 
</Directory>

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]
Comments:

Post a Comment:
Comments are closed for this entry.
About

Tourists looking out over an Opal mine
I'm a Product Manager in Server Technologies, working on scripting languages and developer-access.
Email: christopher.jones@oracle.com
Twitter: http://twitter.com/ghrd
Book: Free PHP Oracle book
Download: PHP Linux RPMs with the OCI8 extension
Links: OTN PHP Developer Center

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today