Index: branches/5.2.x/core/kernel/managers/rewrite_url_processor.php =================================================================== diff -u -N -r15343 -r15374 --- branches/5.2.x/core/kernel/managers/rewrite_url_processor.php (.../rewrite_url_processor.php) (revision 15343) +++ branches/5.2.x/core/kernel/managers/rewrite_url_processor.php (.../rewrite_url_processor.php) (revision 15374) @@ -1,6 +1,6 @@ Application->GetVar('_mod_rw_url_'); if ( $url ) { - foreach ($this->_urlEndings as $url_ending) { - if ( substr($url, strlen($url) - strlen($url_ending)) == $url_ending ) { - $url = substr($url, 0, strlen($url) - strlen($url_ending)); - $default_ending = $this->Application->ConfigValue('ModRewriteUrlEnding'); - - // user manually typed url with different url ending -> redirect to same url with default url ending - if ( ($url_ending != $default_ending) && $this->Application->ConfigValue('ForceModRewriteUrlEnding') ) { - $target_url = $this->Application->BaseURL() . $url . $default_ending; - - trigger_error('Mod-rewrite url "' . $_SERVER['REQUEST_URI'] . '" without "' . $default_ending . '" line ending used', E_USER_NOTICE); - $this->Application->Redirect('external:' . $target_url, Array ('response_code' => 301)); - } - - break; - } - } + $this->_redirectToDefaultUrlEnding($url); + $url = $this->_removeUrlEnding($url); } $cached = $this->_getCachedUrl($url); @@ -177,6 +163,68 @@ } /** + * Detects url ending of given url + * + * @param string $url + * @return string + * @access protected + */ + protected function _findUrlEnding($url) + { + if ( !$url ) { + return ''; + } + + foreach ($this->_urlEndings as $url_ending) { + if ( mb_substr($url, mb_strlen($url) - mb_strlen($url_ending)) == $url_ending ) { + return $url_ending; + } + } + + return ''; + } + + /** + * Removes url ending from url + * + * @param string $url + * @return string + * @access protected + */ + protected function _removeUrlEnding($url) + { + $url_ending = $this->_findUrlEnding($url); + + if ( !$url_ending ) { + return $url; + } + + return mb_substr($url, 0, mb_strlen($url) - mb_strlen($url_ending)); + } + + /** + * Redirects user to page with default url ending, where needed + * + * @param string $url + * @return void + * @access protected + */ + protected function _redirectToDefaultUrlEnding($url) + { + $default_ending = $this->Application->ConfigValue('ModRewriteUrlEnding'); + + if ( $this->_findUrlEnding($url) == $default_ending || !$this->Application->ConfigValue('ForceModRewriteUrlEnding') ) { + return; + } + + // user manually typed url with different url ending -> redirect to same url with default url ending + $target_url = $this->Application->BaseURL() . $this->_removeUrlEnding($url) . $default_ending; + + trigger_error('Mod-rewrite url "' . $_SERVER['REQUEST_URI'] . '" without "' . $default_ending . '" line ending used', E_USER_NOTICE); + $this->Application->Redirect('external:' . $target_url, Array ('response_code' => 301)); + } + + /** * Returns url parsing result from cache or false, when not yet parsed * * @param $url @@ -314,9 +362,34 @@ */ public function parse($string, $pass_name = 'pass') { + // external url (could be back this website as well) + if ( preg_match('/external:(.*)/', $string, $regs) ) { + $string = $regs[1]; + } + $vars = Array ($pass_name => Array ('m')); - $url_parts = $string ? explode('/', trim(mb_strtolower($string, 'UTF-8'), '/')) : Array (); + $url_components = parse_url($string); + if ( isset($url_components['query']) ) { + parse_str($url_components['query'], $vars); + } + + if ( isset($url_components['path']) ) { + if ( BASE_PATH ) { + $string = preg_replace('/^' . preg_quote(BASE_PATH, '/') . '/', '', $url_components['path'], 1); + } + else { + $string = $url_components['path']; + } + + $string = $this->_removeUrlEnding(trim($string, '/')); + } + else { + $string = ''; + } + + $url_parts = $string ? explode('/', mb_strtolower($string, 'UTF-8')) : Array (); + $this->_partsToParse = $url_parts; if ( ($this->HTTPQuery->Get('rewrite') == 'on') || !$url_parts ) { @@ -450,7 +523,7 @@ * @return string * @access protected * - * @todo Should find a way, how to determine what rewrite listerner page is it + * @todo Should find a way, how to determine what rewrite listener page is it */ protected function _parsePage(&$url_parts, &$vars) { @@ -808,7 +881,7 @@ { return count($this->_partsToParse) > 0; } - + /** * Builds url *