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?
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.
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.
On my Ubuntu LAMP installation, I solved this problem with the following 2 changes.
sudo a2enmod rewrite
.AllowOverride All
Then restart the Apache server: service apache2 restart
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With