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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -