vendredi 29 avril 2016

Laravel 5 routes and mod_rewrite

I have a simple routes.php file, that looks like this:

Route::group(['middleware' => 'cors', 'prefix' => 'api'], function () {
  Route::post('users', 'Api\UsersController@save');
  Route::get('users/{userId}/leagues/', 'Api\UsersController@saveFavoriteLeague');
});

Once I put my application to server, I couldn't get to any of the routes executed. I was getting 404 exception.

I tried to make an obvious error in routes.php file, by putting 123 at the top of the file. Then I hit http://ift.tt/1Ta85KB, and I was expecting error page, that there is a syntax error, but that didn't happen (still getting 404). However, when adding something like this:

Route::get('/', function() {
   return 'Hello';
});

and hitting home route mydomain.com, I was able to see at first syntax error, and then after fixing it, Hello.

I spent hours until I discovered that mod_rewrite, wasn't enabled on the remote server.

Can someone put more light on this? Why my requests didn't reach routes.php (not even to show that there is an syntax error), but instead 404 page was returned. Why mod_rewrite made it to work? How could / reached the route.php, but /users e.g. didn't?

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire