Strip trailing slash ( / ) from URL route strings.
See original GitHub issueHey 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:
- Created 4 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
btw: you can use
"/path/?"
to match an optional slash…I am seeing this issue again. From the history of routing.py it looks like #707 might have been reverted by #704?