Fixed route filters, ending slash

Jake Bunce

Well-known member
Affected version
2.0.7
I'm not sure if you would consider this a bug, but at the least it is a parity issue between XF1 and XF2.

Create a route filter like this in both XF1 and XF2:

Screen Shot 2018-07-06 at 9.57.30 PM.webp

In XF1 you can then visit:

http://yoursite.com/index.php?important

...and the result is that it redirects you to:

http://yoursite.com/index.php?important/

...and subsequently loads the proper target.

In XF2 it works differently. Trying to request this URL:

http://yoursite.com/index.php?important

...simply gives you a XF 404.

I have a customer who desires the XF1 behavior in XF2.
 
I just wanted to reply and let the devs know that this seems to be a fairly serious bug as this affects all custom routes in XF2. this has broken dozens and dozens of urls on my website. i'm running nginx but i haven't been able to come up with a redirect scheme that solves this issue without creating a redirection loop. I've tried this solution on stack overflow, but it doesn't work for links that manage things like posting threads, etc:

https://stackoverflow.com/a/3912675

the only solution i've been able to come up with is to add each custom route individually in the vhost config:

Code:
  #fix xf2 bug
  rewrite /book$ $scheme://$host$uri/ permanent;
  rewrite /fest$ $scheme://$host$uri/ permanent;
  rewrite /contact$ $scheme://$host$uri/ permanent;
  rewrite /about$ $scheme://$host$uri/ permanent;
  rewrite /podcast$ $scheme://$host$uri/ permanent;

which is obviously a huge pain in the arse. not to mention any word-of-mouth sharing of urls is not likely to include a trailing slash; when was the last time you included a trailing slash when writing a url on a piece of paper for someone?

so this is resulting in a lot of traffic going to 404 pages in xf2 (xf1 added the slash properly). is there any chance there will be a fix for this anytime soon? am i crazy in thinking this is a major bug? i guess i'm just looking for a dev to maybe comment on this and at least state if a fix is coming so i'm not stuck in limbo wondering if this will ever be fixed.
 
Just tested this on all route filters we have and as reported, without the /, Xenforo won't redirect and will show 404 instead.
Please fix this. Thank you
 
That seems to be generally broken without friendly URLs.
42937982904_589e1c76ea_o.png

/index.php?test/
aswell
/index.php?whats-new/
now both result in 404.
At least the original whats-new route should not be affected by this at all.

Edit: Nvm, that does not even work with friendly URLs activated. Maybe I'm doing something wrong?
 
@S Thomas
If you have a xf1 installation, you can easily check that the same settings for test/ filter will behave differently on xf1 and xf2. Hence it is suggested it's a xf2 bug since it breaks things that worked on xf1.
 
You misunderstood me, I can reproduce your bug and not only that, there's a pretty related one to it aswell. whats-new/ is a standard route and that one gets broken when you create an invalid route filter. In my example, there is no route test/, so obviously that route filter will fail. But it will also break the original whats-new/ route which really should not happen.
 
This is sorted for the next release, XF 2.0.10.

If you'd like to implement a change now, please add the following to src/config.php. Ideally, remove it before you upgrade to XF 2.0.10:

PHP:
if (\XF::$versionId < 2001070)
{
   $c->extend('router', function(\XF\Mvc\Router $router)
   {
      $router->addRoutePreProcessor('prefilter', function(\XF\Mvc\Router $router, $path, \XF\Mvc\RouteMatch $match, \XF\Http\Request $request = null)
      {
         if (strlen($path) && strpos($path, '/') === false)
         {
            $path .= '/';
            $match->setPathRewrite($path);
         }

         return $match;
      }, true);
      return $router;
   });
}
 
Top Bottom