Append trailing slash on all URLs

Hey all,

Was wondering if there’s a way to force a trailing slash on all route helpers.
I tried to specify a trailing slash in the router get("/foo/bar/", FooController, :bar),
but foo_path(@conn, :bar) outputs without the trailing slash /foo/bar.

I would also like to have it trailing in resources, so for a :show path, it would output /foo/:id/.

I personally hate the trailing slash, but I’m migrating from a system which forces it.
I also already have nginx rewriting anything w/o a trailing slash, but wanted to get the links pointing correctly to avoid unnecessary rewrites.

Thanks for any help!

did you found an answer ? I’m searching for it as well(for the same reasons :frowning: )

No, I ended up not using the route helpers.

@josevalim said some days ago that “Phoenix ignores the trailing slash when matching…”:

If you match with trailing slash in the router file, it would be useful for the helper functions to return with trailing slashes as well. I have no idea if there’s some technical detail that doesn’t easily allow for this.

trailing slash vs non-trailing slash is like the www vs non-www discussion :smile:


Hmm, that would be a useful way to make it explicit on which to use.

1 Like

Well for what is worth i did it other way around with simple Plug :wink: which is redirect 301 the url with “/” to no-slash(I prefer this way). It was for SEO optimisation our “expert” said that url with trailing slash “are better for SEO” :ghost:but after some googling google blog itself says that it doesn’t really matter far as you do 301 from one style to another it doesn’t count as double content.
I post the link here in case someone else like me will have to do it for “SEO reasons”