views:

1273

answers:

2

I am experiencing strange behavior with my Zend Framework application.

I run this url, hoping to get index controller run the 1234567890 action.

http://hello.com/index/1234567890?test=http%3A%2F%2Fworld.com%2Findex.php

I however get exception like this:

Message: Invalid controller specified (4567890)

And strangely all URLs that are on the page now link to:

http://hello.com/index.php/index/1234567890

Instead of:

http://hello.com/index/1234567890

Notice that the index.php string that gets falsely injected into URLs has 9 characters, it is same number as gets cut of the index/1234567890 string to get the wrong controller name.

Another thing is that injected index.php correlates with index.php in url encoded get parameter from the example.

What is wrong? Is it a bug in Zend? Or am I doing something wrong?

This is my .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
A: 

MultiViews could cause this behavior. Try to disable it:

Options -MultiViews
Gumbo
I changed Options All for in my project alias to Options All -MultiViews if that is what you meant but it did not help. I think they were not enabled anyway.
Josef Sábl
I don’t know exactly if this notation is allowed. So try to split them into two declarations.
Gumbo
Have you tried RewriteLogLevel to see the internal processing?
Gumbo
+2  A: 

You didn't put much in the way you've tried to debug this so I wandered over to my own localhost and gave your url a shot. Low and behold mine does the same thing, I tried two different modrewrite methods:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php

And

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

They both were doing the same thing. After spending quite some time playing with the url and looking at what the request parameters looked like on my error page all I could come up with is either there is a major glitch in the default routing patterns in Zend Framework or there's something wonky about using the filename your modrewrite is sending requests to in the url.

So I changed my main index.php file to main.php and respectively in my modrewrite and it works fine, double checked that having main.php in the url would not mess it up and it doesn't.

So while not promising anything, if you rename your index.php (that gets written to and includes your bootstrap) to main.php or whatever you please and reflect that in your modrewrite you should be all set!

Good luck!

Erling Thorkildsen