.htaccess rewrite URL with a question mark “?”

后端 未结 2 1101
忘了有多久
忘了有多久 2020-11-30 14:11

My aim is this URL:

component/users/?view=registration

To:

registration.html

the .htaccess

相关标签:
2条回答
  • 2020-11-30 14:26

    You need to use %{QUERY_STRING} to capture the query string data:

    RewriteCond %{QUERY_STRING} ^view=(.*)$
    RewriteRule ^component/users/?$ %1.html? [R=301,L]
    

    The above rule/condition will take the value of the query string view and use it to form your redirect if the path component/users matches.

    0 讨论(0)
  • 2020-11-30 14:35
    RewriteRule ^component/users/\?view=registration$ registration.html$ [R=301,L]
    

    You need a \ because ? is part of a regular expression. To Use it as a string u need to escape it with a \

    Linktip: http://ole.michelsen.dk/tools/regex.html

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