ZF-4491: Support the new Microsoft URL Rewrite Module for IIS 7.0
Description
Microsoft has recently released its own rewrite module for IIS7.0. (See: http://learn.iis.net/page.aspx/460/…). I was trying to get it to work with your quick start application and found out that it is not completely working as expected. This because this new module uses the HTTP_X_ORIGINAL_URL header instead of the HTTP_X_REWRITE_URL header as used by the isapi_rewrite extension. As a consequence I always got the index controller and action for every request made and thus never got the error page for calls to bogus controllers/actions. Exception: when using the http://localhost/myapplication/index.php/… syntax, it already works fine.
As a newbie to the Zend framework I have no idea if what I did is correct and works in all cases, but as an experienced developer I managed to get it to work by doing a global search for all uses of HTTP_X_REWRITE_URL and adding an additional if branch for the HTTP_X_ORIGINAL_URL as well:
Find results: Zend\Controller\Request\Apache404.php(50): if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch Zend\Controller\Request\Apache404.php(51): $requestUri = $_SERVER['HTTP_X_REWRITE_URL']; Zend\Controller\Request\Http.php(381): * $_SERVER['HTTP_X_REWRITE_URL'], or $_SERVER['ORIG_PATH_INFO'] + $_SERVER['QUERY_STRING']. Zend\Controller\Request\Http.php(389): if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch Zend\Controller\Request\Http.php(390): $requestUri = $_SERVER['HTTP_X_REWRITE_URL']; Zend\OpenId.php(110): if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { Zend\OpenId.php(111): $url .= $_SERVER['HTTP_X_REWRITE_URL'];
Changes made (this is for OpenId.php, other files have similar changes) (basically add an if elseif for the new HTTP_X_ORIGINAL_URL header): if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) { // check this first so IIS will catch $url .= $_SERVER['HTTP_X_ORIGINAL_URL']; } elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
Comments
Posted by Brian Reich (breich) on 2009-03-16T09:41:47.000+0000
The simplest way that I've found to get around this issue is to add the following lines to my bootstrap file, prior to any calls to Zend_Controller_Front::getInstance():
/* * For IIS 7.0 Rewrite Module - allows use of "clean" URL syntax instead of * index.php/controller/action/ by copying original URL value set by the rewrite * module to the server variable expected by the Rewrite Router. */ if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
}
Posted by Bruno B B Magalhães (brunobbmagalhaes) on 2009-08-12T09:23:03.000+0000
To fix this issue, the method setRequestUri within Zend_Controller_Request_Http class must be changed as this (line 383):
I've already tested it in a development server running Windows Server 2003 SP3 + IIS 7.0 + Rewrite Module, and worked as expercted.
Best Regards, Bruno B B Magalhães
Posted by Matthew Weier O'Phinney (matthew) on 2009-08-15T13:57:52.000+0000
Reopening, as no patch has been applied. :)
Posted by Ian Unruh (iunruh) on 2012-05-31T16:05:23.000+0000
This needs to be fixed. IIS 7.0+ is default in Windows Server 2003, Server 2008, Server 2008 R2, and Windows 7. This issue affects anyone using those operating systems with IIS and the URL Rewrite module.
Posted by Evan Coury (evan.pro) on 2012-06-13T16:57:37.000+0000
This is fixed in ZF2 with PR 1424.
Posted by Frank Brückner (frosch) on 2012-06-14T17:22:47.000+0000
Fixed in svn r24842 by rob (Rob Allen).