Order of your routes is very important.
Aug 21, 2020
12
Level 1
Laravel 7 404 Error with Route with more than 2 Levels
I'm facing a wired issue with Laravel where routes with multiple parameters (both mandatory/optional) aren't working.
Environment Information:
- Local: Windows, XAMPP, PHP 7.3
- Production: Ubuntu 18.04, PHP 7.4
Initially, I suspected issue with .htaccess file but that seems not to be an issue. This works perfectly on my Local, but for some reason, that doesn't work on Ubuntu Server.
The following code works perfectly.
Route::any('route/me/','Tst@routeme');
However, any of the following doesn't work:
Route::any('route/me/here/','Tst@routeme');
Route::any('route/me/here/{id?}','Tst@routeme');
Route::any('route/me/here/and/here','Tst@routeme');
Basically any number of parameters added after Level 2 (route/me) doesn't work at all and throws 404 | Not found Error. Any suggestions where I can look up to fix this out, please?
Update:
I posted 3 examples of routes as an example that I tried "individually" but none of them worked.
My .htaccess file is :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Level 1
Try clearing your
Run
php artisan route:cache
and then
php artisan route:clear
1 like
Please or to participate in this conversation.