0

The title says it pretty well... How does Laravel implement clean URL and redirect them to the right Controllers.

Some frameworks like CakePHP use .htaccess to redirect everything to a FrontController which then dispatch the requests but laravel doesn't use .htaccess so i am bit confused.

3
  • 2
    Actually Laravel does use a .htaccess file, see the source. Commented Aug 7, 2013 at 21:20
  • @Rubens, your right. It does use it in the 'Public' folder but what about the other folders. In version 3, there is application, bundles, Laravel and storage folders which doesn't have .htaccess Commented Aug 7, 2013 at 21:31
  • In both version (3 or 4) your document root will be the public folder. So this is the only directory accessible from the outside world, the other directories are never intended to be accessible from the outside world. Commented Aug 7, 2013 at 21:47

2 Answers 2

1

Laravel use the concept of "routing", where all clean url are usually defined and mapped to something that will resolve to a view, such as controller action, anonymous functions, plain string, etc...

Each request will be caught by a file located at: public/index.php (that is done by a .htaccess file located at the same location). That index.php file will boostrap or illuminate the Laravel framework, and Laravel will run your code. How is it done? Routing.

The routing configuration is stored in a file located at app/routes.php where a route might look as follows:

Route::get('/users',            'UserController@showUsers');
Route::get('/users/create',     'UserController@createUser');
Route::post('/users/create',    'UserController@processCreateUser');
Route::get('/users/edit/{id}',  'UserController@createUser');
Route::post('/users/edit/{id}', 'UserController@processCreateUser');

More information about routing can be read at the documentation. I strongly recommend you to read the docs since routing are quite powerful in Laravel.

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

Comments

1

Laravel sites use the public/ folder as their document root. You'll find the .htaccess file in there.

3 Comments

how does Laravel define that public/ is the root folder of the application?
You'll need to set the document root as public/ in Apache.
@Gab, you should double check the docs regarding installation instructions. They clearly says: It is recommended that you either set the public folder as your site's documentRoot (also known as a web root) or to place the contents of public into your site's root directory and place all of Laravel's other files outside the web root. Check that part: Installation paths Saying that, is your responsibility to define the public directory as your document root via your web server.

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.