Framework: Post requests to Route::post('/') returns 301 redirect

Created on 2 Jul 2013  路  9Comments  路  Source: laravel/framework

I have a form on my first page like this

{{ Form::open() }}
    {{ Form::text('invite_code', null, array('placeholder' => 'Skriv in din injudningskod h盲r...')) }}
    {{ Form::submit('G氓 vidare') }}
{{ Form::close() }}

The routes looks like this.

Route::get('/', 'InviteController@getInvite');
Route::post('/', 'InviteController@postInvite');

When posting I only get 301 and is redirected to the Route::get route.
If I change the form and routes to use /invite when using posts instead all works fine...

Route::get('/', 'InviteController@getInvite');
Route::post('/invite', 'InviteController@postInvite');

Is there a reason I can't send post requests to first page?

Most helpful comment

nope, did not solve it. Still getting 301

My problem got solved when I sent post request without forward slash

All 9 comments

Try just passing a blank string to the route instead of a backslash. You may also have to have your form post to the homepage without a trailing slash.

nope, did not solve it. Still getting 301

Tried in incognito and also clearing cache with artisan. Nothing helped. But after reading the thread you linked the problem seems to be with chrome. It automatically adds a trailing slash every time I visit localhost/project/public. No matter how, it always adds it :-p . Solved it by defining which action to be used by the form

{{ Form::open(array('action' => 'InviteController@postInvite')) }}

Thanks! Was looking so long for this. I didn't know that a trailing slash would result in a redirect. Especially since my local vagrant environment worked fine but production was causing issues. Finally solved all my issues :)

nope, did not solve it. Still getting 301

My problem got solved when I sent post request without forward slash

Clearing browser cache did it for me.
The issue was caused by messed middleware in app/Http/Middleware, that Chrome had cached

nope, did not solve it. Still getting 301

My problem got solved when I sent post request without forward slash

same here!,,, why?

Thank god! Was tearing my hair out. The end forward slash work locally but not on prod, only difference I can think of is on prod I have SSL enabled.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

digirew picture digirew  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments

ghost picture ghost  路  3Comments

fideloper picture fideloper  路  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments