gotham-rs / gotham

A flexible web framework that promotes stability, safety, security and speed.

Home Page:https://gotham.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redirect URLs to their canonical equivalent

gralpli opened this issue · comments

URLs with and without trailing slashes are considered to be different. Serving the same content behind a URL with and without a trailing slash may be considered duplicate content by search engines.

There should be a way to redirect all URLs (via 301 Moved Permanently) to their canonical equivalent. That includes removing empty segments as well as redirecting to the variant with or without trailing slash (that should be selectable – I prefer trailing slashes, because I can then easily add subpages later).

EDIT: Trailing slashes should not be added if a file is accessed, so this seems to be more complicated after all. One can also consider interpreting . and .., this might even be necessary if HTML pages use relative URLs (like <img src="../images/1.jpg">), but I don’t know to what extent browsers are already required to resolve this before sending the request.

commented

Why do you need to serve the same content under two different urls (with and without a trailing slash) in the first place? These urls are certainly different and I believe gotham's router does not alter trailing slashes, neither in your router definitions nor in the urls requested from the client, and I believe it should remain this way.

If you require to implement this in your server, you're stuck with the "run something before the router" problem (unless you want to add all routes twice) - this has been a long-standing issue in gotham (#292).

I don’t really want to serve different content, I want to avoid serving the same content under two different URLs. And a URL with a trailing slash is different from a URL without a trailing slash. It’s common practice to redirect one to the other, but Gotham currently doesn’t seem to have way to accomplish this.

Today is my first day with Gotham. I’m currently evaluating different frameworks to see which one serves my needs.