XF 1.2 Route Filters

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:

ss-2013-04-05_14-48-30.webp


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! :)
 
Clickfinity,

I'm sure this is accomplished using the PHP backend, and doesn't require mod_rewrite + .htaccess. If your URLS are "index.php?forums" and you wanted to reroute forums to boards, your links would look like "index.php?boards".

At last that's how I've gathered and what seems logical to me as a programmer.

Jeremy
 
Mike... THANK YOU!!!! I have been trying to accomplish this using apache and the htaccess on my own and have been totally discouraged. I always knew that it could be done somehow. XF is now at SUPER status!!! IMHO.
 
Will be be allowed to give page names '.html' extension with route filters?
It appers to me to become XF answer to vbSEO.. YESSSSSS
 
To people asking what's possible, think about how it works. It works on the "route" part of the URL. Here that's the part immediately after http://xenforo.com/community/; if we didn't have friendly URLs enabled, it'd be after http://xenforo.com/community/index.php?.

When a link is generated by XenForo, we look at the route filters and do a replacement on that URL before outputting it to the HTML. What you enter in the find box will automatically match from the start of the route (threads/route-filters.47946/page-3). If it matches, it'll be replaced by the replace box. The URL will still be prefixed by the xenforo.com/community/(index.php?) part, so you can't override that.

The constraints are that the find and replace entries must both start with a "prefix", basically one or more alphanumeric or dash characters. You can use placeholders to do find/replaces (after the prefix) bit, but the only thing you have access to is what's in the URL already. If you want to make hierarchical URLs, you'd have to define that for every URL that you want to change. (And obviously, there is some performance overhead for filters - it's the same for every feature really.)

When reading a URL and figuring out where it goes, we do the opposite: find the "replace" and replace it with the "find". The rules are the same: it replaces at the start of the route part. This is then passed to XenForo as normal, so we simply see the standard routes internally.

You can create conflicts or route filters that disable access to other routes. A good example would be replacing threads/ with forums/. You'd simply disable access to any forum view pages (like the thread list), because that URL would be turned into threads/forum-name.1/.
 
I'd like to see this work with wildcards.

For example, assume I had an add-on which made

/path1/path2/path3

I could then impute

/path1/*/path3 = /path1/new1/path3

So the outcome would be

/path1/new1/path3
 
http://www.sociallyuncensored.eu/forums/blog/lost-friends/
Would this be something one could do in 1.2 ?
The problem I see with that is that XenForo does not use the textual links at all - they're literally there for decoration and usability. That is why all XenForo links either include or are solely the ID numbers after the point, because the IDs are how XenForo identifies pretty much everything. So although I speak without any authority, I can tell you pretty safely that route filters won't be able to do that unless you define a filter for every single blog post - as mentioned by Mike above.

You could, however, change xfa-blog-entry to blog. :D
 
The problem I see with that is that XenForo does not use the textual links at all - they're literally there for decoration and usability. That is why all XenForo links either include or are solely the ID numbers after the point, because the IDs are how XenForo identifies pretty much everything. So although I speak without any authority, I can tell you pretty safely that route filters won't be able to do that unless you define a filter for every single blog post - as mentioned by Mike above.

You could, however, change xfa-blog-entry to blog. :D
That would be good enough :)
 
I think there is indeed an add-on which allowed me to change a path for some add-ons .... But it wasn't able to do all of it

http://www.sociallyuncensored.eu/forums/xfa-blog-entry/lost-friends.196/

The above for example. The bold text I would have preferred the path to just

http://www.sociallyuncensored.eu/forums/blog/lost-friends/

Would this be something one could do in 1.2 ?
Could you not do something like:
Find: xfa-blog-entry/{title}.{num:digit} (where {num:digit} is the ID - or can't you target IDs?)
Replace: blog/{title}

I'm not 100% sure of the specifics regarding removing IDs, but hey.
 
Will be be allowed to give page names '.html' extension with route filters?
It appers to me to become XF answer to vbSEO.. YESSSSSS

Maybe if you want to hurt your SEO... Search engines couldn't care less what your extension is, having one is just gives you an unrelated keyword thus reducing weight on the important ones.

Screen-Shot-2013-04-09-at-6.49.42-PM.png
 
Maybe if you want to hurt your SEO... Search engines couldn't care less what your extension is, having one is just gives you an unrelated keyword thus reducing weight on the important ones.

What is your point? I was simply asking if it could be done.... really not concerned with SEO
 
What is your point? I was simply asking if it could be done.... really not concerned with SEO
As someone who has been helping websites with SEO, I have to agree with what rollthebones said. If it has no benefits then there is no reason to use it, in fact there is reason not to use it. Unfortunately, no RT can't replace every rewrite function vbseo offers. But it offers some of the functionality.
 
Top Bottom