转义符号在$ _GET htaccess的重写规则失败 [英] htaccess rewrite rule with escaped ampersand in $_GET fails
问题描述
我遇到了在与htaccess的重写规则一起GET参数有问题。 下面是urlen code()'版的链接;我用的是重写规则重定向到的index.php,最后,在index.php一的print_r($ _ GET)。 正如你所看到的,urlescaped符号不是静态变量值的一部分,而是和出乎我的期望得到除preTED为变量分隔符。 为什么?
初始链接:
< A HREF =静态/游戏,技%26艺术实验室>链接< / A>
的.htaccess:
重写规则^静态/(.*)$ /index.php?static=$1 [L]
的index.php:
阵列([静态] =>博弈技[-Arts实验室] =>)
嗯,好吧。有趣。它似乎还有保持的符号专门躲过了特殊的解决方案。使用 [B]
标志的规则集。
重写规则^静态/(.*)$ /index.php?static=$1 [L,B]
这是应该的时候插了 $ 1
占位符urlen code特殊字符。它只能与Apache 2.2的工作,但是我相信。
找了几个参考:
- <一个href="http://www.dracos.co.uk/$c$c/apache-rewrite-problem/">http://www.dracos.co.uk/$c$c/apache-rewrite-problem/
- <一个href="http://stackoverflow.com/questions/2842294/mod-rewrite-with-question-marks-and-ampersands-with-php">mod_rewrite问号和&号(与PHP)
- <一个href="http://www.mediawiki.org/wiki/Manual:Short_URL/Ampersand_solution">http://www.mediawiki.org/wiki/Manual:Short_URL/Ampersand_solution
I am encountering a problem with a get parameter in conjunction with a htaccess rewrite rule. Below is the urlencode()'ed link; the rewrite rule I use to redirect to index.php, and lastly, a print_r($_GET) on the index.php. As you can see, the urlescaped ampersand is not part of the value for variable static, but instead and contrary to my expectation gets interpreted as a variable seperator. Why?
Initial link:
<a href="static/Game-Tech-%26-Arts-Lab">link</a>
.htaccess:
RewriteRule ^static/(.*)$ /index.php?static=$1 [L]
index.php:
Array ( [static] => Game-Tech- [-Arts-Lab] => )
Ah, okay. Interesting. It seems there is a special solution for keeping that ampersand specifically escaped. Use the [B]
flag for Rewriterules.
RewriteRule ^static/(.*)$ /index.php?static=$1 [L,B]
This is supposed to urlencode special characters when interpolating the $1
placeholder. It only works with Apache 2.2 however I believe.
Found a few references:
- http://www.dracos.co.uk/code/apache-rewrite-problem/
- mod_rewrite with question marks and ampersands (with PHP)
- http://www.mediawiki.org/wiki/Manual:Short_URL/Ampersand_solution
这篇关于转义符号在$ _GET htaccess的重写规则失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!