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

Best way to handle missing trailing slashes in routes?

Discussion in 'XenForo Development Discussions' started by Jaxel, Feb 19, 2014.

  1. Jaxel

    Jaxel Well-Known Member

    Okay, lets say I have a URL: domain.com/prefix/string

    What I would like to do is retrieve this string as a parameter and send to actionIndex.

    The problem then becomes a missing trailing slash.

    The url prefix/string would not go to the actionIndex. It would instead try to find actionString. However, if I instead had prefix/string/ (notice the trailing slash), it will go to actionIndex with the parameter being the string. What would be the best way to ensure that "string" gets resolved as a parameter, and never gets seen as an action route?

    I was thinking perfect in the route controller, automatically appending the trailing slash using:
    $routePath = rtrim($routePath, '/') . '/';
    This technically works, and doesn't obfuscate urls such as prefix/string/edit.

    However, would this be best practice, or would there be another way?

Share This Page