Match Question Mark in mod_rewrite rule regex

前端 未结 3 683
一整个雨季
一整个雨季 2020-11-30 06:25

I am looking to rewrite urls with multiple substrings. One substring is being requested as a subdirectory, while any others are requested as normal query string parameters.

3条回答
  •  生来不讨喜
    2020-11-30 07:28

    In addition to using the rewrite flag QSA, you can also use the QUERY_STRING environment variable as shown below:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^([A-Za-z0-9-_]+)/friends$ /friends.php?user=$1&%{QUERY_STRING}
    

    And the URL in question

    http://www.example.com/mark/friends?page=2
    

    will be rewritten to (as specified):

    http://www.example.com/friends.php?user=mark&page=2
    

提交回复
热议问题