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

boynet's avatar

anyone looking for php side solution, create a global middleware with this code: make sure your config.app.url is configured

<?php
namespace App\Http\Middleware;
use Closure;

class RedirectIndexPhp
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //redirect url like example.com/index.php/test to example.com/test
        $find = "index.php";
        $pos = strpos($request->fullUrl(), $find);
        if ($pos !== false) {
            $url = substr($request->fullUrl(), $pos + strlen($find));
            return redirect(config('app.url') . $url, 301);
        }
        return $next($request);
    }
}
1 like
Cronix's avatar

None of this matters if you just don't have any links/anchors in your code that contain index.php. Google only crawls the links that are present in your html. They won't go inserting index.php on their own to see if it works. So just have links like abc.com/something and leave out abc.com/index.php/something and you'll be just fine SEO-wise and won't have duplicate content issues.

SandeepYadav's avatar

Hello everyone you can try below code its 100% working code

Redirect index.php to non index.php

RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^index.php/(.*)$ / [R=301,L]
Previous

Please or to participate in this conversation.