2

I have just installed laravel 5.7. So, In web.php I have defined Route.. Like

Route::get('foo', function () {
    return 'Hello World';
});

But when i Hit the URL -> http://localhost/rp/public/foo

It shows me 404 page not found.

Mh Dip
  • 351
  • 3
  • 15
  • 3
    Your URL should be `http://localhost/rp/foo`, if `.htaccess` is setup correctly. By default in Laravel, you shouldn't have to have `public` in your URL. – Tim Lewis Jan 29 '19 at 16:43
  • @MhDip You should look at [laravel showing 404 for routes](https://stackoverflow.com/questions/13514990/laravel-4-all-routes-except-home-result-in-404-error). – nice_dev Jan 29 '19 at 16:53
  • how about this url `http://localhost/foo` – Kyaw Kyaw Soe Jan 29 '19 at 16:53
  • No solution have not worked for me. i set up public directory files in a root directory and i have also set up properly .htaccess file. Yet it gives me same error.. now my URL look like Route::get('/admin',function(){ return "Welcome Admin" }); – Mh Dip Jan 31 '19 at 05:25

1 Answers1

1

use PHP's built-in development server, you may use the serve Artisan command:php artisan serve

Later you can check in browser like this: http://localhost:8000/foo


If you have to check without artisan serve

Route::get('/foo', function () {
    return 'Hello World';
});

you can check like this(rp is your laravel-project-name): http://localhost/rp/public/foo

you must have a configuration like this in your .htaccess file

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
  • This ain't the solution though. – nice_dev Jan 29 '19 at 16:55
  • No solution have not worked for me. i set up public directory files in a root directory and i have also set up properly .htaccess file. Yet it gives me same error.. now my URL look like Route::get('/admin',function(){ return "Welcome Admin" }); – Mh Dip Jan 31 '19 at 05:25
  • @MhDip Then there will be some problems with your other code, can you please show me the full code of your `routes/web.php` – Udhav Sarvaiya Jan 31 '19 at 05:29
  • my local directory name is rp.. somehow . i have solved this problem.. but... when write code like Route::get('/admin', function () { return "admin"; }); it redirect to .. 404 page but when i write code like Route::get('rp/admin', function () { return "admin"; }); it shows the expected result.. but i don't want to define the root directory .. rp/admin.. like thatt – Mh Dip Jan 31 '19 at 07:43
  • see the comment bro @UdhavSarvaiya. mistakenly i press enter before finish the content :( – Mh Dip Jan 31 '19 at 07:46
  • I'm glad you got the solution @MhDip what is the reason behind your case I don't know but I check my code in my pc and its working properly, you not required project name [check this](https://github.com/laravel/laravel/blob/master/routes/web.php#L14) and [check this also](https://laravel.com/docs/5.7/routing) [Routing](https://laravel.com/docs/4.2/routing) – Udhav Sarvaiya Jan 31 '19 at 08:03