2014-02-07 64 views
2

我想在Symfony2中用一个点来停止路由。因此,例如:Symfony2路由 - 排除.html

/博客/开发(这是罚款)
/blog/developm.ent(需要404)
/blog/development.html(需要404)

哪有我使用yml实现了这一点?这就是我对上面的第一个例子:

s_nerds_blog_category_page: 
    pattern: /blog/{category} 
    defaults: { _controller: SNerdsBlogBundle:Default:category } 

回答

4

在Symfony2的路线要求:

您可以添加正则表达式requirements所请求的网址需要与得到解决为某条路:含有

# This example allows only digits (\d+) for {category} 

blog: 
    path:  /blog/{category} 
    defaults: { _controller: AcmeBlogBundle:Blog:index, category: 1 } 
    requirements: 
     category: \d+ 

Exluding路由点:

# matches only routes not containing a dot 

blog: 
    path:  /blog/{category} 
    defaults: { _controller: AcmeBlogBundle:Blog:index, category: 1 } 
    requirements: 
     category: ^[^\.]*$ 

解释

  1. ^ - 串
  2. 的开始
  3. [^\.]* - 除了.任何字符,任何重复次数
  4. $的 - 字符串的结尾
+0

完美感谢那。 –