在我们的基于ZF的网站中,如果控制器/操作段上的网址包含$$$
或~
,则它不会被捕获为404错误,相反,它们会在没有控制器/操作的情况下登录到控制器/操作符号,但是当它尝试加载视图脚本时,视图脚本文件仍然具有这些符号,从而导致错误。
例如:
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
如果控制器/操作不存在,它们必须被捕获为404错误,并且站点可以捕获404错误。
ex: /badurl$$$, /non/existing~
示例:http://framework.zend.com/index。$$$ / index~
这有什么问题/解决方案吗?
提前致谢!
PS:我们仍在使用ZF 1.0.3,但这也会影响1.8.2中的其他网站。
更新:这是.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
答案 0 :(得分:1)
问题不在您的.htaccess文件中。
您的问题源自调度程序,请参阅1.0.3 Zend_Controller_Dispatcher_Abstract::_formatName()
中的受保护方法。此方法自1.0.3以来也没有改变。因此,升级无济于事。
它实际上是使用preg_replace('/[^a-z0-9 ]/', '', $segment)
从URI中删除所有特殊字符并返回有效的类名。
如果不编写自己的自定义调度程序,则必须使用不同的字母数字字符命名,即/ xxx或/ 000
参见下面的方法:
/**
* 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);
}