question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strip trailing slash ( / ) from URL route strings.

See original GitHub issue

Hey all, an optional trailing slash seems to be pretty standard on most websites, but in Starlette, you must add separate routes to handle them. Example:

routes = [
    Route('/', PlainTextResponse("home")),
    Route('/test', PlainTextResponse("test")),
    Route('/test/', PlainTextResponse("I need to be added separately?!"))
]

app = Starlette(routes=routes)

Could a route = route.rstrip("/") please be added to https://github.com/encode/starlette/blob/master/starlette/routing.py in class Router before running the match so these routes don’t have to be manually added? Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
blueyedcommented, Sep 11, 2019

btw: you can use "/path/?" to match an optional slash…

2reactions
achiencommented, Jan 28, 2020

I am seeing this issue again. From the history of routing.py it looks like #707 might have been reverted by #704?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove a trailing slash from a string(changed from url type) in ...
I want to check if the string ends with a url, and if it does, i want to remove it. Here is what...
Read more >
How to Remove a Trailing Slash From a String in JavaScript?
Introduced in ES6, we can use endsWith() to see if the string ends with a trailing slash and accordingly we can remove it....
Read more >
Remove trailing slash from url - Excel formula - Exceljet
To remove a trailing slash from a URL or path, you can use a formula based on the LEFT and LEN functions. In...
Read more >
Should You Have a Trailing Slash at the End of URLs? - Ahrefs
A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. The trailing slash...
Read more >
Trailing / in route patterns - Slim Framework
Slim treats a URL pattern with a trailing slash as different to one without. That is, /user and /user/ are different and so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found