Can't route properly in Laravel

2020-04-01 00:54发布

问题:

I am very new to laravel and I simply don't get how to route properly, am completely lost. The problem is I can only route a view to localhost/public. For example I can't route a view to "localhost/public/something". Am not even sure my urls are correct. If i leave "something.php" empty nothing will show, but if i add some html it shows only the html no views. Am sure am doing it all wrong. So how does one route a view to a page other than "public/". The routing for index is

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

works okay.

Now how can I achieve the same if do

Route::get('something', function(){
    return View::make('welcome');
});

or

Route::get('/something', function(){
    return View::make('welcome');
});

So i finally got it to work after so many hours. I deleted my laravel installation and did a new one and the problem is gone. Thanks.

回答1:

There's nothing wrong with your code but might be for .htaccess

Please try accessing the route via following URL http://localhost/public/index.php?/something

if it's working, you need to use the alternative .htaccess file provided on Laravel website or see if mod_rewrite is loaded on your Apache.