Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jerauf's avatar

Redirects work locally but not in prod

I've got my redirects in a controller (because I read that would be a better way to do it). Because of the size of my site, they are in a separate route file.

Here's my route:

Route::get('index.php/biography/{id}', [\App\Http\Controllers\RedirectsController::class, 'biographyOverviewRedirect']);

Here's my controller:

public function biographyOverviewRedirect($id) {
    return redirect('biography/'.$id, 301);
}

They are working locally (using Herd) but not in production.

Has anyone had this happen? Any suggestions for a fix?

(I'm still on Laravel 10)

0 likes
9 replies
Glukinho's avatar

How do you think we can investigate your problem if you don't provide neither your code nor errors/logs?

Glukinho's avatar

First, having route with index.php is wrong, you should probably tune your web server to get rid of 'index.php'. Nginx settings are in docs: https://laravel.com/docs/12.x/deployment#nginx

Second, provide full RedirectsController.php file.

Third, what is the error an when it happens?

jerauf's avatar

@Glukinho Google is finding index.php. It's not even a route.

Controller:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class RedirectsController extends Controller { public function biographyOverviewRedirect($id) { return redirect('biography/'.$id, 301); } }

It gives a 404 error.

Glukinho's avatar

@jerauf what URL exactly gives you 404 error?

Also please wrap all code in three backticks:

| ```
| ..code..
| ```
Glukinho's avatar

@jerauf look in Chrome Dev Tools / Network when reaching out this URL. You should see two requests:

  • first gets 302 code + Location header
  • second goes where Location header points and gets 404.

Is it true?

Glukinho's avatar

Do you have a route that corresponds to redirect('biography/...)? Can you show output of command php artisan route:list?

Glukinho's avatar

Also, I don't get the idea of having a dedicated controller just to redirect to another place of your app. Why you can't just return requested data without redirection?

Please or to participate in this conversation.