I need help.
i have a route
how can i redirect it to “/users/”?
because in router it is consider the same. it redirects over and over again.
Can you elaborate on what it is you’re trying to accomplish by doing this? Is it just aesthetic?
i just want to redirect the “/users” to “/users/” but it is consider the same
I get that. I want to understand why you want to do that. Why do you want to have the trailing prefix?
bacause i have an external app ("/users/") and on my route in elixir “/users” i want it to move_permanently to “/users/” when they visit “/users”
It is a semantic distinction made by some API designers, that a trailing slash indicates a collection ressources, while a missing slash indicates a single ressource.
can you post the code that is not working?
This is a guess, but I suppose having
user_path(conn, :index) return
/users/ instead of
Phoenix ignores the trailing slash when matching but it should not remove them when generating a route. So if you do something like
redirect conn, to: "/users/", then it should work.
Append trailing slash on all URLs
Redirects can be cached in browsers, so make sure you test after clearing cache and/or in a private/incognito browser window.
Caching can really be a hard thing… At least for google chrome I had to learn recently, that disabling the cache in the developer toolbar doesn’t actually disable the cache, but only parts of it…