转义符号在$ _GET htaccess的重写规则失败 [英] htaccess rewrite rule with escaped ampersand in $_GET fails

查看:194
本文介绍了转义符号在$ _GET htaccess的重写规则失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了在与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:

这篇关于转义符号在$ _GET htaccess的重写规则失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆