Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

husseinrubaie98's avatar

Laravel Routes return 404 error

Hello,

I've been a while developing websites using Laravel, but it's the first time I encounter such a problem. I have many routes defined in routes/web.php and they're working normally. But when reaching some point (i.e some number of routes), new routes defined at the end below are not working. They're returning a 404 error (Not found), though they're defined, and they're shown when running "php artisan route:list".

When trying to find a solution, I found something related to the ".htaccess" file found in the public folder of the project, and something related to "AllowOverride all" instead of "AllowOverride none", but everything regarding the Apache server was set correctly, and the problem was still there.

And by the way: I'm using wampserver as a local server, and when I runned the project on the embedded server that comes with Laravel (php artisan serve) it also returned the same error.

So, can anyone help me with that? Please, I tried a lot looking for solution, but got nothing. Depending on you :)

0 likes
13 replies
Sinnbeck's avatar

Please post something to go by. Routes file would be a good start (and where it breaks)

Snapey's avatar

most likely you have a route defined that is greedy and catches the route before it gets to your new routes

As suggested, providing your web.php would be really useful

1 like
husseinrubaie98's avatar
<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/



# Below are the welcome pages:

Auth::routes();

Route::get('/', function () {
    return view('en-welcome');
});

Route::get('/en', function () {
    return view('en-welcome');
})->name('en-welcome');

Route::get('/ar', function () {
    return view('ar-welcome');
})->name('ar-welcome');;

Route::get('/en/welcome', function() {
    return view('en-welcome');
});

Route::get('/ar/welcome', function() {
    return view('ar-welcome');
});
/********************************************************* */

# Release Routes    ;   DONE

Route::get('/releases', 'ReleaseController@index')->name('releases.index');
Route::get('/{volume_no}/{issue_no}', 'ReleaseController@show')->name('releases.show');
Route::post('/releases/add', 'ReleaseController@add')->name('releases.add');
/********************************************************* */

# Category Routes   ;   DONE

Route::get('/categories', 'CategoryController@index')->name('categories.index');
Route::get('/categories/{category_id}/edit', 'CategoryController@edit')->name('categories.edit');
Route::post('/categories/add', 'CategoryController@add')->name('categories.add');
Route::patch('/categories/{category_id}', 'CategoryController@update')->name('categories.update');
Route::delete('/categories/{category_id}', 'CategoryController@destroy')->name('categories.destroy');
/********************************************************* */

# Author Routes

Route::get('/authors', 'AuthorController@index')->name('authors.index');
Route::post('/authors', 'AuthorController@add')->name('authors.add');

/********************************************************* */

# Article Routes


Route::get('/home', 'HomeController@index')->name('home');

Route::get('/{article_id}', 'ArticleController@show')->name('article.show');

Route::get('/{volume_no}/{issue_no}/add', 'ArticleController@add')->name('articles.add');

# not implemented yet

Route::post('/{article_id}/edit', 'ArticleController@edit')->name('articles.edit');

Route::post('/{volume_no}/{issue_no}', 'ArticleController@store')->name('articles.store');
Route::delete('/{article_id}', 'ArticleController@destroy')->name('article.destroy');


/********************************************************* */

# Home Routes


/********************************************************* */ ```


This is my routes/web.php file.  The "/home" route is the last route that works normally. All other routes below are not working. Note that when I move one of the routes below upwards, it works. So, this means it's not an error in the routes.

Any thoughts?
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

This route will catch everything

Route::get('/{article_id}', 'ArticleController@show')->name('article.show');

/lalala would hit it as it catches everything. It's the same with all other routes after it also

This would be better

Route::get('article/{article_id}', 'ArticleController@show')->name('article.show');
2 likes
jove's avatar

@sinnbeck doesn't that also include the other ones too? Like

Route::post('/{article_id}/edit', 'ArticleController@edit')->name('articles.edit');
Route::get('/{volume_no}/{issue_no}/add', 'ArticleController@add')->name('articles.add');
husseinrubaie98's avatar

@sinnbeck it worked like magic!!

Everything is working properly, though I just changed "/{article_id}" into "article/{article_id}". But can you explain why's that happening? Note that I have a route "/{volume_no}/{issue_no}" above with the "Release Routes" and it's not problematic.

Sinnbeck's avatar

Sorry seems I was a bit to quick. Didn't notice that. Anyone else see something I am missing?

Anyway. Be careful with loose routes like that. It's easy to hit the wrong one

Can you show an example of a url that didn't work?

Snapey's avatar

The routes are evaluated from top to bottom, and anything this is just one word will be caught. /{volume}/{issue} wont be caught because that requires two parameters with a slash in the middle.

1 like
Sinnbeck's avatar

@snapey That was my thought too, but there are not single word get routes after it (only a delete route)

This is my test and nothing breaks. So my though is that it might be the url that is "special" :)

Route::get('/{volume_no}/{issue_no}', function() {
    'break app';
});

Route::get('/home', 'HomeController@index')->name('home');

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

Route::get('/{volume_no}/{issue_no}/add', function () {
    return 'add';
});
1 like

Please or to participate in this conversation.