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

mvnobrega's avatar

301 redirect from index.php

I need to redirect the exact url https://www.casadapalavra.com.br/index.php to https://www.casadapalavra.com.br

And I'm using the following:

redirectMatch 301 ^casadapalavra.com.br/index.php$ https://www.casadapalavra.com.br

Apparently it works and actually redirects to the homepage, but when I go to test on some redirection site like https://httpstatus.io/ , it says that the redirect went to the same path: http://www .casadapalavra.com.br/index.php

But because of SEO I need to ensure that it is interpreted that the redirect went to the home page (without index.php). I really tried several codes here, but the others caused redirects in urls that also have index.php somewhere in their path and that shouldn't redirect, for example: http://www.casadapalavra.com.br/livros/index .php?code=264

Because the redirect check sites don't understand that the redirect went to the homepage and insist on saying that it was redirected to the same place while in the browser I'm actually taken to the homepage without index.php

I simply need to redirect variations with and without https/http/nowww/www from the path ^casadapalavra.com.br/index.php$ to the home page.

Can anyone guide me? It sounds simple, but everything I've tested doesn't work as expected.

0 likes
3 replies
mvnobrega's avatar

@JakeCausier

Yes that would be a problem, because I need to make an individual redirect to these other urls that contain index.php.

Any suggestion on how to do this?

mvnobrega's avatar

I just realized that the problem must be related to my htaccess. It has a configuration for index.php there. The problem is that this is generating duplicate content, as it is possible to access my site both with the final index.php and without it.

help me solve this

My .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # redirect http://www.example.com to https://www.example.com
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    # redirect http(s)://example.com to https://www.example.com
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

</IfModule>

Please or to participate in this conversation.