mod_rewrite NE flag - When is it helpful to encode special chars in the URL?

前端 未结 2 2052
盖世英雄少女心
盖世英雄少女心 2020-12-29 09:30

I\'ve been looking at the [NE] (noescape) flag in mod_rewrite. After some thought I couldn\'t figure out a situation when I would NOT want to use the f

2条回答
  •  情歌与酒
    2020-12-29 09:53

    The [NE] flag is extremely useful when you are adding the request url as part of - let's say - an authorization signature.

    I just had a bug where authorization was working with .htaccess off but not with it on. It turned out the cause was that redirection was url encoding the items that ended up in the php $_GET parameter. To solve the bug I changed:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*[^/0-9])$ $1/ [R=301,L]
    

    to

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*[^/0-9])$ $1/ [NE,R=301,L]
    

    (the authorization signature is composed of many things, one of these is the request url)

提交回复
热议问题