htaccess的德codeS%2B和+都进入太空 [英] htaccess decodes both %2B and + into space
问题描述
我似乎无法能够使用mod_rewrite时以任何方式传递一个+
手动添加这到查询字符串 _tags = C%2B%2B +堆栈+溢
,被正确地转换为 C ++堆栈溢出
。
但使用mod_rewrite时(使用或不使用[NE]标志)
重写规则^标签/([\\ w _ \\ - \\ + \\%] +)?$ tags.php _tags = $ 1 [QSA,L]
然后,它会转换为 C堆栈溢出
(注意3个空格)。使用[B]国旗让我ç+++堆栈溢出+
代替。
目标是,无论?_标记= C%2B%2B +堆栈+溢
和 /标签/ C%2B%2B +堆栈+溢
。
应该导致 C ++堆栈溢出
。
我使用的空间作为分隔符分裂的标记。
$标签= array_unique(爆炸(,$ _REQUEST [_标签]))
目标是,无论
?_标记= C%2B%2B +堆栈+溢
和/标签/ C%2B%2B +堆栈+溢
应导致C ++堆栈溢出
。
块引用>该URL标准说
/标签/ C%2B%2B +堆栈溢出+
是语义上等同于ç+++堆栈溢出+
。未指定的长处重新present空格路径组件;在[B]
的行为是正确的。路径和查询组件是故意不同。如果你想包括相同逃脱无论在内容,你应该使用明确的
%20
在preference到+ 避免的区别code>。
您可以尝试通过查看原始的<$ C拿起之间
+
和%2B
的区别$ C> $ _ SERVER [REQUEST_URI] 和采摘它除了手动而不是使用符合标准的PHP解析器给你。但它不太可能是个好主意。I can't seem to be able to pass a "+" in any way when using mod_rewrite.
Manually adding this to the query string
_tags=C%2B%2B+Stack+Overflow
, gets properly converted toC++ Stack Overflow
.But when using mod_rewrite (with or without the [NE] flag)
RewriteRule ^tags/([\w_\-\+\%]+)$ tags.php?_tags=$1 [QSA,L]
Then it's converted to
C Stack Overflow
(note the 3 spaces). Using the [B] flags gets meC+++Stack+Overflow
instead.The target is that both
?_tags=C%2B%2B+Stack+Overflow
and/tags/C%2B%2B+Stack+Overflow
.Should result in
C++ Stack Overflow
.I'm using the space as a delimiter for splitting the tags.
$tags = array_unique(explode(" ", $_REQUEST["_tags"]))
解决方案The target is that both
?_tags=C%2B%2B+Stack+Overflow
and/tags/C%2B%2B+Stack+Overflow
should result inC++ Stack Overflow
.The URL standard says that
/tags/C%2B%2B+Stack+Overflow
is semantically equivalent toC+++Stack+Overflow
. Pluses are not specified to represent spaces in path components; the[B]
behaviour is correct.Path and query components are deliberately different. If you want to include the same escaped content in both you should avoid the difference by using the unambiguous
%20
in preference to+
.You could try to pick up the difference between
+
and%2B
by looking at the raw$_SERVER[REQUEST_URI]
and picking it apart manually instead of using the standards-compliant parsers PHP gives you. But it's not likely a good idea.这篇关于htaccess的德codeS%2B和+都进入太空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!