Replies: 2 comments 2 replies
-
ExampleHere is an example for the change in the Change:
to:
This will exclude the For testing, see this page or this page FYI: The trailing slash will be filtered out by the routing system (not sure which class), so a trailing slash request will be handled as one without it. (If you use standard |
Beta Was this translation helpful? Give feedback.
-
How-ToHere a small how-to including the code for the above mentioned middleware. 1) Edit
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
When making a PUT, PATCH or DELETE request to a standard API resource route (
api/somemodel/{id}
), but with a trailing slash, the.htaccess
file redirects this to the non-trailing-slash url. This is great for regular pages I imagine (as discussed way back at #23), but it loses the post data and makes it a GET request.This might be confusing for any user of the API (they get back the right resource, but unchanged and no error/warning). To warn this 'misuse' of the trailing slash for endpoints, I created a Middleware that would spot the trailing slash and throw a descriptive error. But the trailing slash is already gone because
.htaccess
made the redirect.Suggestion:
Edit the
.htaccess
to exclude all/api/
(or other global API endpoint starter from.env
?) urls from the 'trailing-slash to non-trailing-slash' redirect.Or is there a better way to handle this?
Beta Was this translation helpful? Give feedback.
All reactions