views:

24

answers:

1

I'm setting up a Zend application, and went through the basic steps of setting up modrewrite on my development station, and writing an .htaccess file (shown below). Now, when I go to the root of my project, Zend works properly, calling the controller and displaying the appropriate page.

However, when I call any controller, I would expect it to redirect to the same index.php file, which would in turn direct it to the appropriate controller and action (e.g. myurl/controller/action would be read by myurl/index.php which would then redirect to the action appropriately).

I suspect that the issue is somehow related to how I've set up my .htaccess file, since calling the base url does work properly. But I haven't been able to figure out what's wrong. Does anyone have a suggestion?

Options +FollowSymLinks  
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)/(.*)$ index.php [NC,L]
RewriteRule ^(.*)/(.*)/(.*)$ index.php [NC,L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)$ index.php [NC,L]
RewriteRule ^.*$ index.php [NC,L]
+1  A: 

Okay, here's what it was.

My DOCUMENT_ROOT is set to /var/www while my application is running out of /var/www/app1 with everything set up in there. Because of the line RewriteBase / it was redirecting to the DOCUMENT_ROOT instead of to the APPLICATION_ROOT. I fixed it by changing that line to:

RewriteBase /app1

and now everything works perfectly.

Elie
(Sorry, went to lunch, then a meeting) Ahh, of course, the `RewriteBase`. The [module documentation](http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase) suggests that it's necessary to have in most cases, but this is typically untrue (things should have also worked fine if you had omitted it altogether), so I find that a bit misleading. Anyway, good catch, +1
Tim Stone
Thanks! Your comment about DOCUMENT_ROOT led me onto that, since I have several sites running off my single Apache server, but only this one is using modrewrite at the moment.
Elie