Trailing slash in Flask route
<p>Take for example the following two routes.</p>

<pre><code>app = Flask(__name__)

@app.route("/somewhere")
def no_trailing_slash():
    #case one

@app.route("/someplace/")
def with_trailing_slash():
    #case two
</code></pre>

<p>According to <a href="http://flask.pocoo.org/docs/0.11/quickstart/#variable-rules" rel="noreferrer">the docs</a> the following is understood:</p>

<ul>
<li><p>In case one, a request for the route <code>"/somewhere/"</code> will return a 404 response. <code>"/somewhere"</code> is valid.</p></li>
<li><p>In case two, <code>"/someplace/"</code> is valid and <code>"/someplace"</code> will redirect to <code>"/someplace/"</code></p></li>
</ul>

<p>The behavior I would like to see is the <em>'inverse'</em> of the <strong>case two</strong> behavior. e.g. <code>"/someplace/"</code> will redirect to <code>"/someplace"</code> rather than the other way around. Is there a way to define a route to take on this behavior?</p>

<p>From my understanding, <code>strict_slashes=False</code> can be set on the route to get effectively the same behavior of case two in case one, but what I'd like to do is get the redirect behavior to always redirect to the URL <em>without</em> the trailing slash.</p>

<p>One solution I've thought of using would be using an error handler for 404's, something like this. (Not sure if this would even work)</p>

<pre><code>@app.errorhandler(404)
def not_found(e):
    if request.path.endswith("/") and request.path[:-1] in all_endpoints:
        return redirect(request.path[:-1]), 302
    return render_template("404.html"), 404
</code></pre>

<p>But I'm wondering if there's a better solution, like a drop-in app configuration of some sort, similar to <code>strict_slashes=False</code> that I can apply globally. Maybe a blueprint or url rule?</p>