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

deicool's avatar

Routes in Laravel

Hello

I am a newbie.

I am having a problem regarding 'Routes in PHP'.

The following route is not working:

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

When I change it to the below mentioned lines, it works.

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

Any idea where I am going wrong.

Please advise.

Thanks.

0 likes
16 replies
Sinnbeck's avatar

What error are you getting? How are you running laravel? What exact url are you visiting?

Muetze's avatar

Do you have the routes possibly in the cache, and 'php artisan route:clear` tried?

Otherwise, it can also be due to the order of the routes, if there are several routes with /product.

Tray2's avatar

I suggest that you remove the trailing slash

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

So that the route becomes

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

Or even

Route::get('product', function () { return view('welcome'); });

If that still doesn't work, make sure that you have mod_rewrite enables if you use apache.

laravel_ninja's avatar

Run

php artisan optimize:clear

then reload your page . it'll work

Sinnbeck's avatar

@musman_anwar Please be careful suggesting that people should cache their app in dev. Instead suggest that they clear the cache

php artisan optimize:clear
1 like
deicool's avatar

The command "php artisan route:list" gives me the output:

POST _ignition/execute-solution ..................................................................... ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController

GET|HEAD _ignition/health-check ................................................................................. ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController

POST _ignition/update-config .............................................................................. ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController

GET|HEAD api/user .....................................................................................................................................................................

GET|HEAD products .....................................................................................................................................................................

GET|HEAD sanctum/csrf-cookie ........................................................................................ sanctum.csrf-cookie › Laravel\Sanctum › CsrfCookieController@show

deicool's avatar

My apache conf file is as follows (in the sites-enabled folder) if it helps

<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/laravel/public

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
deicool's avatar

Could there be a missing PHP library?

My server configuration:

t2 micro on aws

ubuntu 20

php 8.1

Laravel Framework 9.44.0

nielsnl's avatar

Having read this thread, and your other one, I can only recommend that you watch some more video courses on this website.

Your questions are very basic and your problems easily avoided. Watching the videos on this site, and coding along with Jeffrey, takes some time, but it's worth it.

You'll save a lot of time and frustration in the long run by actually understanding how Laravel works, rather than 'fiddling till it works'.

1 like
deicool's avatar

@nielsnl

You summarized what i am doing perfectly.

I will watch Jeffrey's videos and try that way (Guess should take a week's time)

Thank You

1 like

Please or to participate in this conversation.