Home > Enterprise >  Laravel one specific route gives 403 (nginx)
Laravel one specific route gives 403 (nginx)

Time:09-17

All routes on my production website are working fine except for the /blog route which gives a 403 forbidden (nginx).

In web.php

Route::get('/blog', [BlogController::class, 'index'])->name('blog.index');
Route::get('/blog/{slug}', [BlogController::class, 'post'])->name('blog.post');
Route::get('/blog/preview/{slug}', [BlogController::class, 'postPreview'])->name('blog.post.preview');

I have deployed via Forge and Envoyer and didn't change anything in the server configs.

CodePudding user response:

When using the default Laravel configuration the rewrite rule that rewrites all requests to index.php in order for the router to process them first checks if the request does not correspond to an existing file or folder. This is done usually to serve resources like e.g. js files directly without hitting Laravel. However this means if you have a folder that matches the same name as a route then the folder will take priority over the route.

In your case you have a folder called public/blog and nginx correctly returns a 403 because by default accessing directories to view their contents is forbidden.

  • Related