Zend Framework - Error when URL has $$$ or ~ on controller/action segment
In our ZF based site, if a url contains $$$
or ~
on the controller/action segment, it was not caught as 404 error, instead, they landed on the controller/action without the symbol, but when it tries to load the view script, the view script file is still having those symbol thus causing an error.
For example:
site.com/index$$$
script 'index$$$/index.phtml' not found in path
site.com/index-$$$
script 'index-$$$/index.phtml' not found in path
site.com/index~
script 'index~/index.phtml' not found in path
site.com/index/index~
script 'index/index~.phtml' not found in path
They must be caught as 404 error and out site can catch 404 errors if the controller/action is non existing.
ex: /badurl$$$, /non/existing~
Example: http://framework.zend.com/index.$$$/index~
Is there any existing issues / solutions to this?
Thanks in advance!
PS: we are still using ZF 1.0.3 but this also affects other sites which are in 1.8.2.
Update: This is the content of .htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/search$
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule . /search/?%1 [R=301,L]
# Redirect all https urls to http
# These开发者_高级运维 are the pages excluded on the redirection
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/minify/.*
RewriteCond %{REQUEST_URI} !^/myaccount/.*
RewriteCond %{REQUEST_URI} !^/akamai/.*
RewriteCond %{REQUEST_URI} !^/navigation/.*
RewriteCond %{REQUEST_URI} !^/cache/.*
RewriteCond %{REQUEST_URI} !^/includes/.*
RewriteCond %{REQUEST_URI} !^/images/.*
RewriteCond %{REQUEST_URI} !^/pdf/.*
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
######################################################
# if non-PHP file is requested, display the file #
RewriteRule \.(js|ico|txt|gif|jpg|png|css|xml|swf|zip|pdf|gz)$ - [L,NC]
# if PHP file is requested and it exists, display the file #
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.php$ - [L]
# redirect everything else to controller #
RewriteCond %{REQUEST_URI} !^/server-status.*
RewriteRule .+$ index.php [L]
# Disable Etags
FileETag none
The problem is not in your .htaccess file.
Your problem is originating in the dispatcher see the protected method in 1.0.3 Zend_Controller_Dispatcher_Abstract::_formatName()
. This method hasn't changed since 1.0.3 either. So, an upgrade won't help.
It's actually removing all the special characters from the URI using preg_replace('/[^a-z0-9 ]/', '', $segment)
and returning a valid class name.
Without writing your own custom dispatcher, you will have to use different naming with alphanumeric characters i.e. /xxx or /000
See Method Below:
/**
* Formats a string from a URI into a PHP-friendly name.
*
* By default, replaces words separated by the word separator character(s)
* with camelCaps. If $isAction is false, it also preserves replaces words
* separated by the path separation character with an underscore, making
* the following word Title cased. All non-alphanumeric characters are
* removed.
*
* @param string $unformatted
* @param boolean $isAction Defaults to false
* @return string
*/
protected function _formatName($unformatted, $isAction = false)
{
// preserve directories
if (!$isAction) {
$segments = explode($this->getPathDelimiter(), $unformatted);
} else {
$segments = (array) $unformatted;
}
foreach ($segments as $key => $segment) {
$segment = str_replace($this->getWordDelimiter(), ' ', strtolower($segment));
$segment = preg_replace('/[^a-z0-9 ]/', '', $segment);
$segments[$key] = str_replace(' ', '', ucwords($segment));
}
return implode('_', $segments);
}
精彩评论