-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[Query] Trailing slash doesn't match routes. #23
Comments
I have been having the same issue when you create Resource Controller using Route::resource('test', 'TestController') and creating the controller using ''php artisan controller:make TestController". Then when you browse to /test or /test/create or /test/1 it works fine but when you add a trailing slash like /test/ or test/create/ it throws NotFoundHttpException. Just wondering if this will remain how it is or if it is a bug to be fixed? |
I'm also having the same issue, anything with a trailing slash doesn't route and just shows an error. |
Duplicate content has to be taken into account when handling this. The proper solution, if anything, would be to redirect to one of the two variants (but only if the other one of them is defined). |
Just don't use trailing slashes. |
I don't think that's really a solution. Users may use trailing slashes. We may construct our URLs specifically forgoing them, but a user may still type a URL that includes one. We should be able to cope. Traditionally, the segments of a URL are emulating the folder structure. Where although I have found some web services with APIs that insist upon one format over the other, or that use Even It is of course preferable that a single page does not exist at two different addresses, but at the very least it should redirect from one to the other. |
It's possible to fix this using .htaccess, by rewriting or redirecting to url either with or without trailing slash. It's also possible to enable both variants. Although I agree this should be changed so that na url works with or without /$. |
Just came across this issue too. Any URL with a trailing slash now returns a NotFoundHttpException since updating to the latest version of L4 this morning. I'm also of the opinion that Laravel should redirect to one or the other. |
# |<---- Preferably using up to 50 chars --->|<------------------->| # Example: # Add feature for a user to like a post # (Optional) Explain why this change is being made # |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->| # (Optional) Provide links or keys to any relevant tickets, articles or other resources # Example: Github issue laravel#23 # (Optional) List all co-authors, so version control systems can connect teams. # Example: Co-authored-by: Name <[email protected]> # (Optional) Tags suitable for searching, such as hashtags, keywords, etc. # Example: Tags: authentication, login, security # --- COMMIT END --- # === Remember to === # * Capitalize the subject line # * Use the imperative mood in the subject line # Imperative verbs usage: # - Add = Create a capability e.g. feature, test, dependency. # - Drop = Delete a capability e.g. feature, test, dependency. # - Fix = Fix an issue e.g. bug, typo, accident, misstatement. # - Bump = Increase the version of something e.g. a dependency. # - Make = Change the build process, or tools, or infrastructure. # - Start = Begin doing something; e.g. enable a toggle, feature flag, etc. # - Stop = End doing something; e.g. disable a toggle, feature flag, etc. # - Optimize = A change that MUST be just about performance, e.g. speed up code. # - Document = A change that MUST be only in the documentation, e.g. help files. # - Refactor = A change that MUST be just refactoring. # - Reformat = A change that MUST be just format, e.g. indent line, trim space, etc. # - Rephrase = A change that MUST be just textual, e.g. edit a comment, doc, etc. # * Do not end the subject line with a period # * Separate subject from body with a blank line # * Use the body to explain what and why vs. how # * Can use multiple lines with "-" or "*" for bullet points in body # -------------------- # === Use semantic versioning === # - Add, Start: Increment SemVer MINOR version when there is a new capability. # - Drop, Stop: Increment SemVer MAJOR version when there is an incompatibility. # - Fix, Bump, Make, Optimize, Document: Increment SemVer PATCH version. # - Refactor, Reformat, Rearrange, Redraw, Reword: Increment SemVer PATCH version. # -------------------- # === Usage === # Put the template wherever you want. # Example: # ~/.gitmessage # # Configure git to use the template file by running: # git config --global commit.template ~/.gitmessage && git config --global commit.cleanup strip # # Or manually add the template file to the ~/.gitconfig file: # [commit] # template = ~/.gitmessage # cleanup = strip # --------------------
# |<---- Preferably using up to 50 chars --->|<------------------->| # Example: # Add feature for a user to like a post # (Optional) Explain why this change is being made # |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->| # (Optional) Provide links or keys to any relevant tickets, articles or other resources # Example: Github issue laravel#23 # (Optional) List all co-authors, so version control systems can connect teams. # Example: Co-authored-by: Name <[email protected]> # (Optional) Tags suitable for searching, such as hashtags, keywords, etc. # Example: Tags: authentication, login, security # --- COMMIT END --- # === Remember to === # * Capitalize the subject line # * Use the imperative mood in the subject line # Imperative verbs usage: # - Add = Create a capability e.g. feature, test, dependency. # - Drop = Delete a capability e.g. feature, test, dependency. # - Fix = Fix an issue e.g. bug, typo, accident, misstatement. # - Bump = Increase the version of something e.g. a dependency. # - Make = Change the build process, or tools, or infrastructure. # - Start = Begin doing something; e.g. enable a toggle, feature flag, etc. # - Stop = End doing something; e.g. disable a toggle, feature flag, etc. # - Optimize = A change that MUST be just about performance, e.g. speed up code. # - Document = A change that MUST be only in the documentation, e.g. help files. # - Refactor = A change that MUST be just refactoring. # - Reformat = A change that MUST be just format, e.g. indent line, trim space, etc. # - Rephrase = A change that MUST be just textual, e.g. edit a comment, doc, etc. # * Do not end the subject line with a period # * Separate subject from body with a blank line # * Use the body to explain what and why vs. how # * Can use multiple lines with "-" or "*" for bullet points in body # -------------------- # === Use semantic versioning === # - Add, Start: Increment SemVer MINOR version when there is a new capability. # - Drop, Stop: Increment SemVer MAJOR version when there is an incompatibility. # - Fix, Bump, Make, Optimize, Document: Increment SemVer PATCH version. # - Refactor, Reformat, Rearrange, Redraw, Reword: Increment SemVer PATCH version. # -------------------- # === Usage === # Put the template wherever you want. # Example: # ~/.gitmessage # # Configure git to use the template file by running: # git config --global commit.template ~/.gitmessage && git config --global commit.cleanup strip # # Or manually add the template file to the ~/.gitconfig file: # [commit] # template = ~/.gitmessage # cleanup = strip # --------------------
Just a simple one. I tried creating the following route:
But this route is then only accessible at
example.com/hello
and notexample.com/hello/
, which throws aNotFoundHttpException
. Obviously, creating the route forhello/
then means the route is no longer accessible at 'example.com/hello'. This is exactly what is supposed to happen, since the route didn't match, but it might not be what is expected to happen.Type any URL on the Laravel 4 documentation site, absent-mindedly include a trailing slash, and you won't find the page.
This could be a feature when creating RESTful APIs (when a URI resource with a trailing slash is considered different from one without), but for standard navigation it could be a common query; especially since "Pretty URLs" commonly append a trailing slash for neatness.
To avoid this, users could simply define routes twice, in my case, for both
hello
andhello/
.However, I'm pretty sure doing this for every route for which a trailing slash could be a possibility would be quite annoying. On the other hand, you also wouldn't want to assume and use the
.htaccess
file to automatically add the slash automatically to all routes.tl;dr Not sure if bug or feature, and merely a 'gotcha' for new users.
The text was updated successfully, but these errors were encountered: