Support the ongoing development of Laravel.io →
Installation Configuration

Anyone knows how to make laravel work in a subfolder specifically when posting a form on the same page?

Route::get('/','HomeController@getIndex');
Route::post('/','HomeController@postIndex');

Ex form URL: http://localhost/laravel. Alias added on apache. ...Alias /laravel /www/laravel/public

When you submit the form on this page, the route does not catch it and just return the index page.

However, when you specify index.php on url or add a trailing slash on form action (http://localhost/laravel/), routes catches the post event. It will also work when you specify other url in action like ...array('url' => 'post-index')

All works well when I use virtual host, but my requirements is to install the app in subfolder. Tried playing on htaccess but had no luck.

Last updated 3 years ago.
0

How did you open the form tag?

I think this should work

{{ Form::open(['action' => 'HomeController@postIndex']) }}
Last updated 3 years ago.
0
Solution

Just change/create a different post URL as a work around. Reported as BUG

Last updated 3 years ago.
0

@lucasfercunha

Not working route:

Route::post('/', 'HomeController@postIndex');
{{Form::open(array('class'=>'form-horizontal validate','action'=>'HomeController@postIndex' ))}}

Form will work if you change the route below.

Route::post('post-index', 'HomeController@postIndex');
Last updated 3 years ago.
0

This solution:

Form will work if you change the route below.

Route::post('post-index', 'HomeController@postIndex');

forks fine, thanks!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

yajra yajra Joined 11 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.