mod_rewrite RewriteRule to handle HTML Entities

前端 未结 2 819
被撕碎了的回忆
被撕碎了的回忆 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

    For any rewrite to work, the rewrite engine must be on, but perhaps you already have that fixed:

    # following statement must come before any other rewrite statements
    # and must be enabled per virtual host configuration
    RewriteEngine On
    

    The ampersand is a special metacharacter. Apparently the people that have copied and pasted your links did so inside an editor which duely escaped the ampersands into & (or, more technically correct, & if it happened inside an a-tag). I'm not 100% sure, but I find it likely that the ampersand should be escaped, try this:

    RewriteRule \& \&
    

    To find out how the rewrite goes, what it rewrites and why, you should turn rewrite logging on (make sure Apache can write to the location of RewriteLog):

    RewriteLog "somepath.log"
    RewriteLogLevel 3
    

    where level 9 is the highest.

提交回复
热议问题