1

I successfuly created redirecting in my routing, if page is 1, redirect to main controller without URL parameter page. (SEO prevention for dublicate content). So I have this route rules:

default_blog:
    path:     /                                               
    defaults: { _controller: AcmeBlogBundle:Default:index, page: 1}

default_blog_page_first:
    path:     /page/1
    defaults:
        _controller: FrameworkBundle:Redirect:redirect
        route: default_blog
        permanent: true

default_blog_page:
    path:     /page/{page}
    defaults: { _controller: AcmeBlogBundle:Default:index}
    requirements:
        page: \d+

It works, in my pagination. If i click on my first page (/page/1) i will be redirected on /, but is it possible that it will already transformed in generating path? Just, if default_blog_page will have parameter page = 1 it will automatically transformed to default_blog?

So, my pagination will looks like this:

URL => Page
-------------------
/ => 1 , /page/2 => 2

In any twig template:

path('default_blog_page', {'page': 1})

if detects page = 1, it will automatically changed to:

path('default_blog')

Is it possible?

4

1 回答 1

2

Ok I think I understand what you want to do, and yes, it's possible !

Here is the trick. Edit the default_blog_page route by this code :

default_blog_page:
path:     /{type}/{page}
defaults: { _controller: AcmeBlogBundle:Default:index, type: "page", page: 1}
requirements:
    page: \d+
    type: page

With this route, if you set the page param, it will automatically add the default type value, "page" but if it's the default values, it won't. Although you can remove your redirection routes because this route handle all cases.

Hope this helps :)

于 2013-11-11T14:21:49.537 回答