开发者

RewriteRule and the number sign “#”

I'm trying to make a friendly URL through RewriteRule but it keeps ignoring # as part of the variable value.

The line on .htaccess is as simple as this

RewriteRule ^key/(.+)/$ index.php?key=$1  

and the requested URL is

http://www.example.com/key/c%23/  

but I'm only gett开发者_如何学Cing c as get variable and not c%23.

What exactly am I doing wrong?


Finally after some digging, I managed to pull this off.

It just needs the B flag on RewriteRule to escape non-alphanumeric characters such as #

RewriteRule ^key/(.+)/$ index.php?key=$1 [B]


%23 is a hash symbol (#), so it (and anything after it) doesn't actually get parsed by mod_rewrite. The actual URL therefore is http://www.foo.com/key/c, without any %23. Other dash-codes work fine, though.


%23 is a hash mark (#). I'm guessing the browser is interpreting the hash as an anchor and not passing it on to the server. For instance, if you user http://www.foo.com/key/c%20/ you'll get "c[space]".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜