网址中的双斜线. [英] double slash in URLs.
本文介绍了网址中的双斜线.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Zend Route问题.
Zend Route issue.
通常正常.
http://www.example.com/course-details/1/Physics-Newtons-Law
但是,如果我在网址中输入一个额外的斜杠,则会调用我的Error控制器的noauthAction.
But if I type in an extra slash in the url, the noauthAction of my Error controller gets called.
无法使用的网址示例.
http://www.example.com/course-details//1/Physics-Newtons-Law
http://www.example.com/course-details/1//Physics-Newtons-Law
在路由定义中是否需要设置一些内容以允许额外的斜杠?
Is there something I need to set in the route definition to allow extra slashes?
在application.ini中路由
Routing in application.ini
resources.router.routes.viewcourse.route = "/course-details/:course_id/:title"
resources.router.routes.viewcourse.defaults.controller = course
resources.router.routes.viewcourse.defaults.action = view
resources.router.routes.viewcourse.defaults.title =
resources.router.routes.viewcourse.reqs.course_id = "\d+"
推荐答案
您可以使用控制器插件来修复常见的URL拼写错误.
You could use a controller plugin to fix common URL typos.
/**
* Fix common typos in URLs before the request
* is evaluated against the defined routes.
*/
class YourNamespace_Controller_Plugin_UrlTypoFixer
extends Zend_Controller_Plugin_Abstract
{
public function routeStartup($request)
{
// Correct consecutive slashes in the URL.
$uri = $request->getRequestUri();
$correctedUri = preg_replace('/\/{2,}/', '/', $uri);
if ($uri != $correctedUri) {
$request->setRequestUri($correctedUri);
}
}
}
然后将插件注册到您的ini文件中.
And then register the plugin in your ini file.
resources.frontController.plugins.UrlTypoFixer = "YourNamespace_Controller_Plugin_UrlTypoFixer"
这篇关于网址中的双斜线.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文