mod_rewrite RewriteRule to handle HTML Entities

前端 未结 2 829
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 16:12

For some reason, we recieving a bunch of inbound traffic on URLs that contain HTML entities.

E.g.

http://www.ourdomain.com/index.php?key1=value1&am

2条回答
  •  青春惊慌失措
    2021-01-03 16:55

    This should do the trick;

    RewriteEngine On
    RewriteCond %{QUERY_STRING} (.*)&(.*)
    RewriteRule .* /index.php?%1&%2 [N,R=301]
    

    This essentially says;

    • Is there an & in the query string?
    • If yes, match everything before and after it, then sandwich them together with an &
    • The N flag in the rule effectively says 'keep doing this until the condition no longer makes a match'

    Check out the mod_rewrite documentation, including RewriteCond and rule flags.

提交回复
热议问题