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

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

问题描述

我遇到一个get参数与htaccess重写规则相结合的问题。
以下是urlencode()的链接;重写规则我用来重定向到index.php,最后是index.php上的一个print_r($ _ GET)。
如你所见,urlescaped和号不是变量static的值的一部分,而是与我的期望相反,被解释为变量分隔符。 为什么?

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?

初始链接:

<a href="static/Game-Tech-%26-Arts-Lab">link</a>

.htaccess:

.htaccess:

RewriteRule ^static/(.*)$ /index.php?static=$1 [L]

index.php:

index.php:

Array ( [static] => Game-Tech- [-Arts-Lab] => )


推荐答案

啊,好的有趣。似乎有一个特殊的解决方案来保持&符号特别逃脱。使用 [B] 标记为Rewriterules

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]

当内插 $ 1 占位符。

找到几个参考资料:

  • 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屋!

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