Search code examples
.htaccesshttp-redirectmod-rewrite

Redirect from all pages with index.php to non index.php


I have this rule for redirect from index.php

RewriteCond %{HTTP_HOST} ^(.*):443$ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^/index.php$ [NC]
RewriteRule ^(.*)index\.php$ https://%1/$1 [L,R=301]

But it works only for address: site.com/index.php to site.com I need to redirect from all adress who contain index.php, for example site.com/categories/rings/index.php to site.com/categories/rings/ Thanks!


Solution

  • Your RewriteCond rules are the problem:

    RewriteRule ^(.*/)?index\.php$ https://%{HTTP_HOST}/$1 [L,R=301]
    

    If you want to keep the port RewriteCond, you can use this:

    RewriteCond %{SERVER_PORT} ^443$
    RewriteRule ^(.*/)?index\.php$ https://%{HTTP_HOST}/$1 [L,R=301]