I need to make some SEO adjustments on a 10 years old code base so I have to proceed with caution.
The task is to do a 301 redirect of https://www.example.com/index.php to https://www.example.com.
The current rules are these:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
# Force WWW
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# Force HTTPS
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# Add a trailing slash to non-files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
# General rules
RewriteRule ^product/(.*)-(.*)/(.*)-(.*)/$ product.php?category_permalink=$1&category_id=$2&product_permalink=$3&product_id=$4 [QSA,L]
RewriteRule ^categories/(.*)-(.*)/page-(.*)/$ categories.php?permalink=$1&category_id=$2&page=$3 [QSA,L]
RewriteRule ^categories/(.*)-(.*)/$ categories.php?permalink=$1&category_id=$2 [QSA,L]
RewriteRule ^categories/$ categories.php [QSA,L]
RewriteRule ^search/(.*)$ search.php?q=$1 [QSA,L]
I tried adding the following rules and it works fine, but it messes up https://www.example.com/admin/ too and the website admin can't login anymore because of that.
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
So what I'm trying to figure out is: how can I do the redirect only for the index.php file in the root, not for other subdirectories?
Is this possible?