2

I am very confused as to why this is happening but here is the issue guys. Basically I am building an app using laravel4 I want to go to this URL

http://app.tld/books

However I get this error every time:

404: The requested URL /books was not found on this server.

However in my routes.php file I have the route defined:

Route::get('/books', 'BookController@index');

I also have a view and relevent method in Controller:

public function index(){
        $books = Book::all();
        return View::make('book.index')->with('books', $books);
    }
17
  • In your vhost, do you have it pointing to the /public directory of the project, or just the project root? Commented Aug 18, 2014 at 18:41
  • Have you ran php artisan dump-autoload ? Maybe Laravel didn't yet see your BookController. Commented Aug 18, 2014 at 18:42
  • Probably you need to run php artisan dump-autoload from command prompt/terminal. Commented Aug 18, 2014 at 18:42
  • Yes it is pointing to /public and also ran the dump auto-load it is strange because in work I can run the project no problem. I've checked it out using SVN into Netbeans Commented Aug 18, 2014 at 18:43
  • 2
    do you have mod_rewrite enabled in apache? Commented Aug 18, 2014 at 18:53

1 Answer 1

1

From the comments we gather that it was an Apache issue, not a Laravel issue (mod_rewrite wasn't enabled -- kudos to @watcher), and I'm glad you sorted it out.

For future reference, it seemed likely to be an Apache issue because Laravel throws PHP exceptions on undefined routes, namely a Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException. If you have debug set to true you'll get a neatly styled stack trace with code highlighting and server/request data, if not you'll get a neatly styled "Whoops, looks like something went wrong." message. If, on the other hand, you get a white screen with Times New Roman messages like "404: The requested URL /books was not found on this server.", Laravel isn't even starting up.

As the comments on your question show, there are many other clues which will tell you that it's not your Laravel routes, though from the code you posted and even the title of the question, you seemed to had narrowed it down to routes, which probably had you looking in the wrong place for a while.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.