3

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

Zahra Badri
  • 1,656
  • 1
  • 17
  • 28

3 Answers3

18

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.

Zahra Badri
  • 1,656
  • 1
  • 17
  • 28
  • Thanks. So much of time wasted, :( do you know why an ending / makes such a problem? – user12414491 Dec 14 '21 at 10:59
  • No. I don't know why that makes problem @user12414491 – Zahra Badri Dec 15 '21 at 09:52
  • Thanks a lot. In my case put backslash in ajax url. – Brindha Aug 27 '22 at 05:49
  • omg, how did i ran into this after so many years of laravel... i feel stupid :-( – cari Sep 15 '22 at 16:39
  • Is it possible to fix that in the back? – Veso Alex Feb 22 '23 at 15:16
  • 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 redirecting – arora Jul 13 '23 at 05:06
  • 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. – Lasantha Jul 29 '23 at 02:06
1

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.

Ali Hyder
  • 41
  • 12
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!

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
ardhiarah
  • 11
  • 3