regex - Remove index.php? with mod_rewrite -
there plenty of answers on removing index.php mod_rewrite in .htaccess need remove index.php? incoming urls , rewrite them all, i.e. /index.php?pagename.php /pagename.php .
either of these work separately, , 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 ?, urls this: example.com/?pagename.php
the issue ? special character in regex, if that's added, understand needs escaped. 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 correctly escape ? in index.php? ?
this answer not work me; leaves ?: mod_rewrite rule remove index.php
and beyond that: there appreciable differences between 2 rewrite rules?
you can use rule in site root .htaccess:
rewriteengine on rewritecond %{the_request} \s/+(?:index\.php)?\?([^&\s]+)\s [nc] rewriterule ^ /%1? [r=301,l]
Comments
Post a Comment