Jishad
Jishad

Reputation: 89

Laravel Routing Does not Work

I am new in LARAVEL framework and I want to run a controller with just function of view a page

class TestController extends BaseController {

    public function index()
    {
        return View::make('hai');
    }
}

I set the routing in routes.php file as given below

Route::get('test','TestController@index');

I tried to run in mozilla with

localhost/laravel/public/test

but it shows

Not Found
The requested URL /laravel/public/test was not found on this server.

is there any problem in my .htaccess page ?

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Any body please help me.

Upvotes: 1

Views: 11520

Answers (3)

tisuchi
tisuchi

Reputation: 129

Simply I refer you not modifying .htaccess file. From http://tisuchi.com/easy-way-handle-routing-laravel/:

Static Page Handling

Handling static page in laravel is one of the easiest way to handle route. Open app/routes.php file and deleted everything from that. Assume that, we are try to route into our following pages- home (example.com), about (example.com/about), contact (example.com/contact). To do so, just write following code in your routes.php file-

/**
 * Static page code
 */

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

# For example.com/about
Route::get('about', function(){
    return View::make('about');
});


/**
 * Naming Route for static Page
 */
# For example.com/contact
Route::get('contatct', array('as' => 'contact', function(){
 return View::make('contact');
}));

If you are really new in Laravel, highly recommend to look into following 2 tutorials-

Ofcourse, don't forget to take a look into official page of laravel.com. Hope, it will work for you.

Have fun...

Upvotes: 0

IamGhale
IamGhale

Reputation: 1240

I'm assuming that you are on Ubuntu machine. To make it work, at first, enable the rewrite module by executing following command in the terminal

 sudo a2enmod rewrite

Second, find "apache2.conf" file in your system, mine is located in

/etc/apache2/apache2.conf

In this file, find the following snippets of code:

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Change "AllowOverride None" to "AllowOverride All". Save the file and restart the apache server by executing following command

sudo service apache2 restart

This should solve the issue. Cheers

Upvotes: 13

Justin Kyle Parton
Justin Kyle Parton

Reputation: 120

Precondition: you will know that you have htaccess working, if when you first installed laravel and went to localhost/laravel/public/, you'd see the laravel logo.

The route is:

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

Regarding Your route: you don't need to explicitly state the function (@index) in the route. Laravel has a default path it follows based on the HTTP request type. Check here (under the heading Actions Handled By Resource Controller) for more details on that.

Upvotes: 0

Related Questions