Apache404.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Controller
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /** Zend_Controller_Request_Http */
  22. require_once 'Zend/Controller/Request/Http.php';
  23. /** Zend_Uri */
  24. require_once 'Zend/Uri.php';
  25. /**
  26. * Zend_Controller_Request_Apache404
  27. *
  28. * HTTP request object for use with Zend_Controller family. Extends basic HTTP
  29. * request object to allow for two edge cases when using Apache:
  30. * - Using Apache's 404 handler instead of mod_rewrite to direct requests
  31. * - Using the PT flag in rewrite rules
  32. *
  33. * In each case, the URL to check against is found in REDIRECT_URL, not
  34. * REQUEST_URI.
  35. *
  36. * @uses Zend_Controller_Request_Http
  37. * @package Zend_Controller
  38. * @subpackage Request
  39. */
  40. class Zend_Controller_Request_Apache404 extends Zend_Controller_Request_Http
  41. {
  42. public function setRequestUri($requestUri = null)
  43. {
  44. $parseUriGetVars = false;
  45. if ($requestUri === null) {
  46. if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
  47. $requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
  48. } elseif (isset($_SERVER['REDIRECT_URL'])) { // Check if using mod_rewrite
  49. $requestUri = $_SERVER['REDIRECT_URL'];
  50. if (isset($_SERVER['REDIRECT_QUERY_STRING'])) {
  51. $parseUriGetVars = $_SERVER['REDIRECT_QUERY_STRING'];
  52. }
  53. } elseif (isset($_SERVER['REQUEST_URI'])) {
  54. $requestUri = $_SERVER['REQUEST_URI'];
  55. } elseif (isset($_SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI
  56. $requestUri = $_SERVER['ORIG_PATH_INFO'];
  57. if (!empty($_SERVER['QUERY_STRING'])) {
  58. $requestUri .= '?' . $_SERVER['QUERY_STRING'];
  59. }
  60. } else {
  61. return $this;
  62. }
  63. } elseif (!is_string($requestUri)) {
  64. return $this;
  65. } else {
  66. if (false !== ($pos = strpos($requestUri, '?'))) {
  67. $parseUriGetVars = substr($requestUri, $pos + 1);
  68. }
  69. }
  70. if ($parseUriGetVars) {
  71. // Set GET items, if available
  72. parse_str($parseUriGetVars, $_GET);
  73. }
  74. $this->_requestUri = $requestUri;
  75. return $this;
  76. }
  77. }