James Wilson
James Wilson

Reputation: 809

Problem with Laravel routes - all sub folder traffic ending up in route view

Sorry - was difficult to give this one a clear title! But I have an issue and a difference between how my local laravel install is dealing with some routes compared to my live server.

Locally, I have this working:

Route::get('/blog', 'BlogController@home');
Route::get('/blog/{post_slug}', 'BlogController@viewPost');

As you can probably guess, I want to serve up a list of posts via the home() function if /blog is hit. Then all other traffic with a "slug" after /blog/, I want to load the blog post.

This all works locally.

However on live,

/blog/my-blog-post

Is serving up the home() function every time.

Where would I start with debugging this. Laravel versions? Server caching?

Upvotes: 0

Views: 102

Answers (1)

Joel Corona
Joel Corona

Reputation: 61

Maybe you can do this in laravel 5.7+

Route::prefix('blog')->group(function () {
    Route::get('/', 'BlogController@home');
    Route::get('/{post_slug}', 'BlogController@viewPost');
});

before just use: php artisan optimize, to clear all cache route and config.

for more info see the docs

Upvotes: 1

Related Questions