Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect URLs to their canonical equivalent #592

Open
gralpli opened this issue Mar 28, 2022 · 2 comments
Open

Redirect URLs to their canonical equivalent #592

gralpli opened this issue Mar 28, 2022 · 2 comments

Comments

@gralpli
Copy link

gralpli commented Mar 28, 2022

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.

@msrd0
Copy link
Member

msrd0 commented Mar 28, 2022

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).

@gralpli
Copy link
Author

gralpli commented Mar 28, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants