Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Routes are Returning a 404, How can I Fix Them?

I've just started learning the Laravel framework and I'm having an issue with routing.

The only route that's working is the default home route that's attached to Laravel out of the box.

I'm using WAMP on Windows and it uses PHP 5.4.3, and Apache 2.2.22, and I also have mod_rewrite enabled, and have removed the 'index.php' from the application.php config file to leave an empty string.

I've created a new controller called User:

class User_Controller extends Base_Controller {

    public $restful = true;

    public function get_index() 
    {
        return View::make('user.index');
    }
}

I've created a view file in application/views/user/ called index.php with some basic HTML code, and in routes.php I've added the following:

Route::get('/', function () {
    return View::make('home.index');
});

Route::get('user', function () {
    return View::make('user.index');
});

The first route works fine when visiting the root (http://localhost/mysite/public) in my web browser, but when I try to go to my second route with http://localhost/mysite/public/user I get a 404 Not Found error. Why would this be happening?

like image 972
JasonMortonNZ Avatar asked Aug 03 '12 07:08

JasonMortonNZ


People also ask

How can I solve this 404 Not Found error even when Route exist?

By adding the . htaccess file at the same folder location of the index. php it solves the 404 page not found error in my laravel Project.

How do I change to 404 in laravel?

Create Custom 404 Error Page You need to create blade views for error pages, move to this path resources/views/ inside here create errors folder and within the directory create 404. blade. php file. It will redirect you to the 404 page if you don't find the associated URL.


Video Answer


3 Answers

On my Ubuntu LAMP installation, I solved this problem with the following 2 changes.

  1. Enable mod_rewrite on the apache server: sudo a2enmod rewrite.
  2. Edit /etc/apache2/apache2.conf, changing the "AllowOverride" directive for the /var/www directory (which is my main document root): AllowOverride All

Then restart the Apache server: service apache2 restart

like image 132
Andrew Vickers Avatar answered Oct 19 '22 22:10

Andrew Vickers


Using WAMP click on wamp icon ->apache->apache modules->scroll and check rewrite_module.

Restart a LoadModule rewrite_module

Note: the server application restarts automatically for you once you enable "rewrite_module"

like image 63
Mario Uvera Avatar answered Oct 19 '22 23:10

Mario Uvera


Have you tried to check if

http://localhost/mysite/public/index.php/user 

was working? If so then make sure all your path's folders don't have any uppercase letters. I had the same situation and converting letters to lower case helped.

like image 37
user1930566 Avatar answered Oct 19 '22 21:10

user1930566