Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel basic routing returns 404

I've recently started learning Laravel but there is one problem which I don't know why it occurs. My current Laravel project is located at wamp/www/codebright. When I access localhost/codebright/public I see the welcome page to Laravel.

When I create a simple routing:

Route::get('my/page', function()
{
    return "Harro world";
});

and trying to access: localhost/codebright/public/my/page it returns with 404 error, not even with Laravel error. I've also tried to access: localhost/codebright/my/page and still.

However, if I type in CMD php artisan serve and open a server on 8000 port and then access: localhost:8000/my/page it works just fine. I would like to know why my first method without the artisan command didn't work.

Thanks in advance!

Note

It seems like that if you have XAMPP installed, none of the problems mentioned above and in the answer comment section are occurring. Basically, if you are using XAMPP, you most likely won't get any error and the program will work just fine.

like image 261
kfirba Avatar asked Dec 30 '25 17:12

kfirba


1 Answers

It is indeed possible to do what you want but if you're not using artisan serve you must have a webserver set up correctly. From your original post you obviously have a webserver set up as you get the welcome page, but it looks to me like one of the following:

  • You don't have the .htaccess file in place
  • Your base vhost (or Apache config if not using a vhost) on your web server setup does not AllowOverride All (which is required to allow .htaccess files to work)
  • You don't have mod_rewrite turned on

You should check these out. As a minimum, Laravel requires a way to turn URIs that don't exist as real files (my/page) into something it can fake a page for. This pretty much requires the use of mod_rewrite and an .htaccess file to specify the rules.


Explanation of the difference between using Apache and artisan serve: artisan serve does not use a 'dumb' webserver like Apache and instead uses a webserver built into PHP which has knowledge of how to handle 'non-existing' URIs that you browse to, which is why you don't need mod_rewrite and the .htaccess file.

like image 102
alexrussell Avatar answered Jan 02 '26 06:01

alexrussell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!