There are plenty of answers on removing index.php with mod_rewrite in .htaccess but I need to remove index.php? from incoming URLs and rewrite them all, i.e. /index.php?pagename.php to /pagename.php .
Either of these work separately, and they remove index.php
1)
RewriteBase /
RewriteRule ^index.php?/(.*)$ $1 [R=301,L]
2)
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
But not the ?, as the URLs look like this: example.com/?pagename.php
The issue is that the ? is a special character in regex, so if that's added, I understand that it needs to be escaped. But neither of these work:
1)
RewriteBase /
RewriteRule ^index.php\??/(.*)$ $1 [R=301,L]
2)
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php\? [NC]
RewriteRule (.*?)index\.php\?/*(.*) /$1$2 [R=301,NE,L]
How do I correctly escape the ? in index.php? ?
This answer does not work for me; it leaves the ?: Mod_rewrite rule to remove index.php
And beyond that: are there appreciable differences between the two rewrite rules?
index.php?pagename.phpare existing links; I can't change them.