我有一个关于 .htaccess 和 QUERY_STRING 的问题。
我尝试使用我的 htaccess 重定向一个 URL,如下所示:
http://mydomain.tld/out/http%3A%2F%2Fotherdomain.tld%3Fparam%3D0
到
http://otherdomain.tld?param=0
我使用带有 REQUEST_URI 的 RewriteCond 和 RewriteRule 来重定向 url,一切正常,因为 REQUEST_URI 在 htaccess 中默认为 urldecoded。
但是,当我通过电子邮件将链接发送到 Hotmail 时,Hotmail urldecodes 斜杠和问号。结果如下所示:
http://mydomain.tld/out/http%3A//Fotherdomain.tld?param%3D0
因此 htaccess 获取链接并尝试重定向它,但由于问号,htaccess “认为”问号后面的所有内容都是 QUERY_STRING。
问题:apache2 不会对 QUERY_STRING 进行 urldecode。那么发生的事情是 htaccess 重定向到
http://otherdomain.tld?param%3D0
这将失败。
所以我的问题是:
我如何告诉 htaccess 对 QUERY_STRING 进行 urldecode 或使用完整请求的 url(urlendcoded 或 urldecoded),包括问号后面的部分
提前致谢!
干杯
最佳答案
您无需添加 [QSA]
到您的重写规则以强制 htaccess 也对查询字符串进行编码。
http://httpd.apache.org/docs/current/en/mod/mod_rewrite.html
关于.htaccess - htaccess QUERY_STRING urldecode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7246497/