1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.2 Route Filters

Discussion in 'Have You Seen...?' started by Mike, Apr 5, 2013.

  1. Mike

    Mike XenForo Developer Staff Member

    Route Filters are a new system in XenForo 1.2 to allow you to change the standard URLs generated by XenForo, including any URLs generated by add-ons.

    It's a fairly simple system to show, but it's very powerful with a little thought. Let's look at what you can set with it:


    Other than a list of route filters, that's really it for the system. So how about a few examples...

    Changing a route prefix
    There's an add-on that does this right now, but we can do it simply from here. For example, if you want to change the resources URL to downloads, you'd just enter resources/ in the find box and downloads/ in the replace box.

    Instantly, any links to http://xenforo.com/community/resources/ would become http://xenforo.com/community/downloads/. URL canonicalization would still happen, but it'd use the new URLs.

    So yes, if you want to change the forums prefix, you can do that.

    Note that the find and the replace fields both need to start with a "prefix" (basically, alphanumeric and dash), so you can't simply remove a route prefix. Doing that would break everything. :)

    Changing a more specific URL
    If you want to change a specific URL--or any URL that begins with a particular string--you can do that with route filters.

    Maybe you have a page with a URL like pages/page-name/ and you'd rather it be page-name/. You can do that by simply entering those in the find and replace boxes respectively.

    You can even create different URLs for specific threads if you wanted to, or maybe a different URL for navigating pages in threads--find: threads/{title}/page-{num:digit}, replace: threads/{title}/{num:digit}-duplicate-posts .

    While it may require a bit of manual work, you could get pretty creative with your URLs. You could even give your page URLs hierarchy, if that's how you store your pages:

    pages/btcc/ -> btcc/
    pages/btcc-2013/ -> btcc/2013/
    pages/btcc-2013-drivers/ -> btcc/2013/drivers/
    pages/btcc-2013-races/ -> btcc/2013/races/

    Creating aliases
    Up until this point, I haven't mentioned the "incoming URL conversion only" option. I've assumed that it hasn't been checked up until now.

    This option lets you allow a URL to work but it doesn't affect what's considered the canonical version. So maybe we want to have releases/114 take us to our 1.1.4 release threads/xenforo-1-1-4-released.47030/ but we want the original URL to be the real URL. We could do that by putting threads/xenforo-1-1-4-released.47030/ in the find box and releases/114 in the replace box. I'm aware this might seem backwards, but the system is written from the perspective of outgoing conversions, so find represents the URL XF is generating; the incoming conversion reverses it. It means that you don't have to swap the values in find/replace if you check/uncheck the incoming only option.

    ...So go wild! :)
    Dadparvar, Liam W, JackIsi and 99 others like this.
  2. ENF

    ENF Well-Known Member

    Unexpected, but welcome!
    DarkGizmo likes this.
  3. Crayo

    Crayo Active Member

    Great stuff again.
  4. Lycaon

    Lycaon Well-Known Member

    Changing specific URL's is something I'll definitely be using.
  5. CyclingTribe

    CyclingTribe Well-Known Member

    I like this - a good way of future-proofing add-ons or XF changes that affect URLs - as well as a great way of getting rid of "/pages/". (y)
    JVCode likes this.
  6. SneakyDave

    SneakyDave Well-Known Member

    Would a person be able to replace old Kier's vB rewrites (showthread, printthread, etc.) with these route replacements? Just remove the showthread.php file and let xF reroute to the correct page?
  7. Mike

    Mike XenForo Developer Staff Member

    Robbo and SneakyDave like this.
  8. erich37

    erich37 Well-Known Member

    great stuff (y)

    So is it now possible to put the RM onto the Homepage with this feature ?

  9. Arty

    Arty Well-Known Member

    That looks very cool.

    Is it possible to dynamically add route filters at run time that would affect only current page?
  10. Mike

    Mike XenForo Developer Staff Member

    You should be able to without much issue. Just need to manipulate what values are shown to the page.
  11. James

    James Well-Known Member

    Excellent addition.
  12. Andrej

    Andrej Well-Known Member

    So this is an replacement of Jake's Route Changer? :) Sounds great to have this in-built now, because it is a must need add-on. :)
  13. Mr_Bob

    Mr_Bob Well-Known Member

    I made the mistake of installing Xenforo in a folder called /forums (rationale /forum is where I had vBulletin installed as I was importing), so this is a very welcome surprise!!!!!:cool:
  14. dutchbb

    dutchbb Well-Known Member

    What's the impact on performance / server load as increasingly more route filters are added?

    I'm not sure about the limitations of this, can we do this for the whole forum:

    Change: http://xenforo.com/community/threads/route-filters.47946/

    to: http://xenforo.com/forum/forum_id/route-filters.47946/ ?


    Change: http://xenforo.com/community/forums/have-you-seen/


    http://xenforo.com/forum/forum_id/ ?

    In other words change the complete URL structure similar to what vbseo used to do for vb, or is the system not designed for this purpose? Also how does it impact SEO, does it deal well with that (i.e. no duplicate content)?
  15. Stuart Wright

    Stuart Wright Well-Known Member

    So is this a user friendly way of doing mod rewrite changes?
    mongy910 and CyclingTribe like this.
  16. euantor

    euantor Well-Known Member

    Yet another amazing feature I didn't know I wanted until it was added. Great work guys!
    tyteen4a03 and Crayo like this.
  17. DRE

    DRE Well-Known Member

    That's one less addon I can uninstall. Thanks Mike. Jake's Route addon is awesome. I never imagined y'all would add it into Xenforo but the fact that you did means your coming closer to the great SEO options of Wordpress more and more every day.
    tyteen4a03 and gordy like this.
  18. TheBigK

    TheBigK Well-Known Member

    Does this also work for addons?
  19. Brogan

    Brogan XenForo Moderator Staff Member

    Very first sentence in the thread.
    ArnyVee likes this.
  20. Slavik

    Slavik XenForo Moderator Staff Member

    Hint read the very first line....
    ArnyVee likes this.

Share This Page