Search code examples
phpzend-frameworkzend-framework-mvc

How to solve the case when users surf to index.php


In Zend framework, using the MVC, if A user surf explicitly to http://base/url/index.php instead of just http://base/url, The system thinks the real base url is http://base/url/index.php/ and according to that calculates all the URLs in the system.

So, if I have a controller XXX and action YYY The link will be
http://base/url/index.php/XXX/YYY which is of course wrong.

I am currently solving this by adding a line at index.php:

$_SERVER["REQUEST_URI"]=str_replace('index.php','',$_SERVER["REQUEST_URI"]);

I am wondering if there is a built-in way in ZF to solve this.


Solution

  • You can do it with ZF by using Zend_Controller_Router_Route_Static (phew!), example:

    Read the manual page linked above, there are some pretty good examples to be found.

    $route = new Zend_Controller_Router_Route_Static(
        'index.php',
        array('controller' => 'index', 'action' => 'index')
    );
    $router->addRoute('index', $route);
    

    Can't say I totally disagree with your approach. That said, others may well point out 5000 or so disadvantages. Good luck with that.