You can add something like the following to the top of the root .htaccess
file to 301 redirect requests for /index.php/<anything>
back to /<anything>
(the canonical URL) - to make your SEO team happy:
# Remove "index.php" from the start of the URL-path
RewriteRule ^index\.php(?:/(.*))?$ https://example.com/$1 [R=301,L]
Where example.com
is your canonical hostname (www vs non-www etc.). By including an absolute/canonical URL here, it potentially avoids multiple redirects later.
The $1
backreference contains the URL-path following index.php
(if any), less the slash prefix - as captured by the RewriteRule
pattern. So, this will also match both /index.php
and /index.php/
and redirect to https://example.com/
(the homepage) in both cases.
This redirect is essential for SEO if you have only recently enabled SEF URLs and the old URLs containing index.php
have already been indexed by search engines, or linked to by external third parties. However, if you implement SEF URLs from the very beginning then it is unlikely that search engines / third parties will find the non-canonical URLs so is unlikely to cause issues (but not impossible).
You don't need to include an additional RewriteEngine On
directive, since this already occurs later in the file. Or, include the above rule immediately after the RewriteEngine
directive - to make it more "readable".
Note that you should first test with a 302 (temporary) redirect to avoid potential caching issues. 301 (permanent) redirects are cached persistently by the browser so can make testing problematic.