DASPRiD / Dash

Flexible PSR-7 compliant HTTP router
BSD 2-Clause "Simplified" License
29 stars 9 forks source link

Add proper handling of trailing slashes #33

Closed DASPRiD closed 9 years ago

DASPRiD commented 10 years ago

In ZF2, people had to be explicit about how trailing slashes in URLs are handled by their routes. Our strictness there was rather pointless, as search engines will see two URLs as the same resource when one ends with a slash and one doesn't.

The proposed solution is to simply rtrim() a possible trailing slash from the incoming path, except if the entire path only consists of a single slash.

bakura10 commented 10 years ago

:+1:

The "search engines will see two URLs as the same resource" is not entirely true. I had this issue one day with CloudFront, which is Amazon CDN (but can be used also for dynamic content), and in its cache, "example.com" and "example.com/" are actually two different resources, and are stored in their cache as two different resources.

We may however add an option to the router so that it forces adding an ending slash.

danizord commented 10 years ago

@bakura10 This can be handled in HTTP server level, see https://github.com/Respect/Rest/blob/develop/public/no-slash.htaccess

DASPRiD commented 10 years ago

@danizord So that was in favour of my idea to rtrim() incoming paths, correct?

danizord commented 10 years ago

@DASPRiD yes.

DASPRiD commented 9 years ago

Well yeah, I agree that it makes more sense to do redirects on the server level, closing.