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! :)
 
XenForo_Link::setIndexRoute

This is for allowing plugins to give the option to set route I assume
At which point and where should it be implement

In the actionIndex of the public controller or _postDispatch / _preDispatch of the plugin that applies the route?


<< btw, very good idea for having both options
 
Last edited:
I just gave it a go

I set this in my listener (my home page plugin in this case uses the route "homepage")

Code:
    public static function routeController(XenForo_Dependencies_Abstract $dependencies, XenForo_Router $router)
    {
        XenForo_Link::setIndexRoute('homepage');
    }
(Wrap that in an option, if you want to give plugin users the option to set home page)

and then set the listener:
init_route.webp

Worked... no issues


I'm liking this a lot, this makes plugins (core/3rd party) even more flexible
 
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.

When I try to use this I get the following error.
preg_match_all() expects at least 3 parameters, 2 given
  1. XenForo_Application::handlePhpError()
  2. preg_match_all() in XenForo/DataWriter/RouteFilter.php at line 129
  3. XenForo_DataWriter_RouteFilter->_countWildcards() in XenForo/DataWriter/RouteFilter.php at line 117
  4. XenForo_DataWriter_RouteFilter->_preSave() in XenForo/DataWriter.php at line 1429
  5. XenForo_DataWriter->preSave() in XenForo/DataWriter.php at line 1368
  6. XenForo_DataWriter->save() in XenForo/ControllerAdmin/RouteFilter.php at line 100
  7. XenForo_ControllerAdmin_RouteFilter->actionSave() in XenForo/FrontController.php at line 335
  8. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
  9. XenForo_FrontController->run() in /home/wreuov/public_html/site.com/testin/admin.php at line 13
 
@Brogan will this new feature also work with prefixes?

For example, right now if I want to filter results within a forum, the URL looks like this:
.../forums/malware-removal.28/?prefix_id=2

It'd be awesome if I could use this kind of URL instead without any hacks:
.../forums/malware-removal.28/solved/
 
Will this form of route filter be any assistance to me to achieve the following:

I am trying to achieve the following, but by having XF installed in the main dir.

mysite.com/index.php <-- this being a custom page within the xf wrapper
mysite.com/forums/ <-- this being xf

I can make this possible by installing XF in a subdir and using the Kotomi script found here in the XF resources and placing this in the main directory, but the problem is that i need / would much prefer xf being installed in the main directory...

Thanks for any feedback on this.

Regards, Darren
 
Last edited:
If you're having support issues, you should probably post in the correct forum - not here.

This forum is sorted by start date.
 
Ok... so, trying to reroute the homepage, to xenporta by replacing the prefix 'portal' with 'index'.

This works as expected but I really dislike the word 'index' in the url.

Any ideas how to fix this?
 
Top Bottom