mod_rewrite with question marks and ampersands (with PHP)

前端 未结 1 685
悲哀的现实
悲哀的现实 2021-01-19 08:06

I have a PHP-based web app that I\'m trying to apply Apache\'s mod_rewrite to.

Original URLs are of the form:
http://example.com/index.php?page=home&x=5

相关标签:
1条回答
  • 2021-01-19 08:13

    Try this:.

    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteRule ^/([a-z]+)(?:$|\?(?:.+)) /index.php?page=$1 [NC,L,B,QSA,NE]
    

    B escapes the backreference (shouldn't be necessary since it is matching [a-z]+, but in case you want to extend it later, it might be useful).

    EDIT: added RewriteCond. EDIT 2: QSA takes care of adding the ampersand.

    0 讨论(0)
提交回复
热议问题