301 Moved Permanently on post ajax requests in laravel
Asked Answered
B

3

10

I upload a laravel project on server; When I run all the ajax post request request run like this:

Request URL: http://example.com/user/register/
Request Method: POST
Status Code: 301 Moved Permanently

Then this run:

Request URL: http://example.com/user/register
Request Method: GET
Status Code: 500 Internal Server Error (from disk cache)

Post method change to get method and return error; How can I solve this?!

I try php artisan cache:clear php artisan config:clear php artisan view:clear But also return error

Briney answered 27/11, 2020 at 1:15 Comment(0)
B
32

I found the answer. put here to help the others. It take so time of me. The problem was so simple. I just remove the backslash from end of url of each post actions.

For example /user/register/ must change to /user/register :|

And cache of the browser must be clear for each page.

Briney answered 27/11, 2020 at 18:26 Comment(8)
Thanks. So much of time wasted, :( do you know why an ending / makes such a problem?Heritage
No. I don't know why that makes problem @HeritageBriney
Thanks a lot. In my case put backslash in ajax url.Froma
omg, how did i ran into this after so many years of laravel... i feel stupid :-(Eckardt
Is it possible to fix that in the back?Homocercal
By default, Laravel's routing configuration ignores trailing slashes. So if there's a mismatch between the URL you're requesting and the route you've defined (e.g., the route is defined as user/register but you're requesting user/register/), Laravel might be trying to "correct" the URL by redirectingRomanism
I found this issue when I was testing in the server, its call the url but its redirected to url without slash, not its ok. thanks in advance.Prepuce
i don't know how can i thanks toWhitehorse
P
5

In my case, It was redirecting from http to https make sure your end domain with the exact domain headers.

Check if your domain is placed on http or on https and match it with the source of the request like with POSTMAN request or Browser Request.

Photophobia answered 27/2, 2023 at 4:21 Comment(1)
in my case it was http to https chnage, and I didn't considered it. TnxBarilla
P
0

In my case for uploading file, my route was same as public directory -> Route::POST('upload/data', [UploadDataController::class, 'upload'])->name('uploadData');

On my public folder: public/upload/data

So I changed the route as upload/uploadData and its perfectly fine!

Puppet answered 9/12, 2022 at 13:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.