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

查看:24
本文介绍了在 $_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:

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

index.php:

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

推荐答案

啊,好的.有趣的.似乎有一个特殊的解决方案可以使该&符号特别逃脱.将 [B] 标记用于重写器.

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 占位符时对特殊字符进行 urlencode.不过我相信它只适用于 Apache 2.2.

This is supposed to urlencode special characters when interpolating the $1 placeholder. It only works with Apache 2.2 however I believe.

找到一些参考资料:

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

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