1
votes

I'm too newbie to Laravel...I have written this route to echo "Hello World", but It errors NotFoundHttpException

This is my routes.php (no other code is in the file but the following):

Route::get('/', function(){
    return "HELLO WORLD";   
});

I have also enable mode_rewrite, and also set AlloOverride to 'all' in apache module.

This is also the URL is use to access the page:

http://localhost/laravel/public/mostafa
3
What URL are u using in your browser? - Duikboot
The route is http://localhost/. - undefined
.get('/') is the root route, so http://localhost/ should show "HELLO WORLD". - undefined
I changed it to "/mostafa" but it does not work. By default it works, without appending any string to "/", while I want to see it work with appended string such as "/mostafa" - user3077503

3 Answers

0
votes

Do:

php artisan serve

Use that URL to visit your website.

You will see that you get some output like:

Laravel development server started on http://localhost:8000

When you have no clue what Artisan is take a look at this; http://laravel.com/docs/artisan

Navigate into your project directory with your command prompt and run there the serve command from above.

Example: enter image description here

0
votes

Sometimes the default .htaccess file located in public folder doesn't work in apache. Try altering the .htacess as mentioned here. Alternatively renaming your laravel project folder would work especially in XAMPP.

0
votes

Some other frameworks treat route definitions as relative to the project web root so a path defined as /foo/bar will match http://example.com/additional/levels/laravel/public/foo/bar and will work without changes even if you move the project tree somewhere else in your public web hierarchy. Laravel, however, considers routes as absolute paths so /foo/bar will only match http://example.com/foo/bar.

The simplest solution is probably to move your code into a separate virtual host and point its document root to laravel/public/. (In this case it seems that's actually the intended set-up.)

(I suppose there's a way to make the framework assume an implicit prefix but I've only been using Laravel for 10 minutes.)