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

jacofda's avatar

Remove index.php from all URLs (for real)

Hello there, I am trying to do SEO, specifically, I want to remove duplicate pages. https://www.laravel.com and https://www.laravel.com/index.php return the same page Even here in Laracast, just try to add "index.php/" after the domain (in all pages).

For the time being I am doing this things: adding a check when I print the canonical

if ( strpos( url()->current(), "index.php" ) !== false )
{   
    return env('APP_URL').$this->slug;
}   

adding a noindex in the webpage if the URL contain index.php

<meta name="robots" content="noindex">

and making sure that all the url('some-page') contain a backslash url('/some-page').

These are all temporary workarounds, I rather find a more solid solutions. All suggestions are welcome.

0 likes
1 reply
martinbean's avatar

@jacofda Well, you shouldn’t be using the robots tag, there’s a dedicated meta tag for specifying canonical URLs:

<meta name="canonical" content="http://example.com/" />

If you don’t want index.php in your URLs then configure your server to perform a 301 redirect when it encounters one.

Please or to participate in this conversation.