Inconsistency with trailing slashes in URIs
If you have a URL with trailing slashes, The trailing slash has to be in the routes, but only if it has a regex segment in it. For example:
'test' => 'pages/test' http://example.com/test/ --> Works 'test/(:segment)' => 'pages/test/$1' http://example.com/test/anything/ --> 404 'test/(:segment)/' => 'pages/test/$1' http://example.com/test/anything/ --> Works
note: doesn't have to be (:segment), could be any regex
I just did a little testing and my findings don't confirm yours in any way. The code always strips a trailing slash from the input URI (whether it's used in Uri::current() or for routing, both come from the same place).
The route with the trailing slash never worked for me, which is logical as it's stripped from the Uri and that route could thus never match anything (trailing slash is either stripped or has a segment after it which isn't matched). While the route without the trailing slash gave the correct page for browser url with or without the URL.
Thus my findings came down to:
'test/(:segment)' => 'pages/test/$1' // works for http://example.com/test/anything/ & http://example.com/test/anything
'test/(:segment)/' => 'pages/test/$1' // can't work
[edited after posting]
I'm sorry for the continued trouble, I can't imagine what I'm doing wrong then. I've tried it several times now, 'test/(:segment)/' -> works, take the slash off, 404.
I tested this on both 1.0.1 and 1.1-dev with the same results, though both on Windows/XAMPP which might matter but really shouldn't judging by the code.
Could you make both your 404 and normal page echo Request::active()->uri->get() and let me know what it shows you with the routes & url combinations?
Here is what I'm seeing:
'test/(:segment)' => 'pages/list/$1', http://example.com/test/anything/ --> pages/404 http://example.com/test/anything --> test/anything
'test/(:segment)/' => 'pages/list/$1', http://example.com/test/anything/ --> test/anything/ http://example.com/test/anything --> pages/404
btw, this was on a server running nginx, and 1.0.1
I was thinking about what you were saying under the other issue and maybe the best solution would be to recommend trailing slashes be removed (and not added) from uris via the web server. Since that's good practice on any website.
Ok, clearly the trailing slash isn't stripped from your uris. Even though that's also possible to do via the webserver, Fuel itself still shouldn't care or be dependent on the webserver. The weird thing is that Fuel actively strips the trailing slash from the uri (check here). I can think of 2 ways this might fail:
- A character encoding problem (though a slash is within the first 128 chars thus should never fail afaik)
- The $uri property is public an can be changed later by the system, somewhere this might go wrong and be set again
Don't have time to look into it now further though, just added comments to remember where I left it.
Ok, I just dumped my fuel install and reinstalled 1.0.1 and it works as it's suppose to. I sincerely apologize for wasting your time on this. I don't know if there was remanence of an older version of fuel or what.