The following code
Route::get('test/{n}', function ($n) {
return $n;
});
App::missing(function () {
return Response::make("Dude, that's a 404 !", 404);
});
works with anything like
http://localhost/myproject/public/test/something
but
http://localhost/myproject/public/test/
redirects to
http://localhost/test
I believe it should instead display
Dude, that's a 404 !
I might have missearched the SO forum, but does anyone have an explanation on this strange behavior ?
EDIT : @Mohammad Walid
Okay, so, I changed my routes.php to this :
Route::get('/', 'HomeController@showWelcome');
Route::get('test', function () {
return 'test';
});
App::missing(function () {
return Response::make("Dude, that's a 404 !", 404);
});
I have not removed the line you talked about in public/.htaccess
.
This works :
base_url/test
But this doesn't (redirects to localhost/test
) :
base_url/test/
How can that be, since you said that removing the line would remove that feature ?
EIDT 2 :
Since it turns out that the problem comes from MAMP not interpreting the trailing slashes redirect condition correctly, a bug report was created in the MAMP bug base :
Its' because Laravel by default redirects trailing slashes.
In app/public/.htaccess file you can find the following:
Change it to:
Have a look at trailing slashes discussion.
Note if you remove the previous line your application won't be able to handle trailing slashes. Ex. if you have a route
Assume
base_url/test/
has been requested instead ofbase_url/test
the server will respond with 404 status.Update
It seems that this is an issue only happens in local development (I use XAMPP).
The expected result for that rule is the following:
But what we actually have in local development:
So what you'll have if you remove the rule:
That's what I meant by
I have tested the rule with online htaccess tester and it worked as expected, that's why I suppose the problem only exists in local development.