gpt4 book ai didi

apache - Lucee URI 编码问题(西里尔文)

转载 作者:行者123 更新时间:2023-11-28 21:48:10 26 4
gpt4 key购买 nike

我刚刚将我们的一个核心应用程序从 Windows+IIS+Coldfusion 迁移到 Ubuntu+Apache+Lucee。第一个大问题是外来字母表的 URI 编码。

例如,尝试访问此 URL http://www.example.com/ru/Солнцезащитные-очки/saint-laurent/ 会在 Apache 访问日志中产生以下记录:

http://www.example.com/ru/%D0%A1%D0%BE%D0%BB%D0%BD%D1%86%D0%B5%D0%B7%D0%B0%D1%89%D0%B8%D1%82%D0%BD%D1%8B%D0%B5-%D0%BE%D1%87%D0%BA%D0%B8/saint-laurent/

好吧,我认为这是正确的 url 编码。然后我在 .htaccess 文件中使用重写规则来获取 url 查询字符串参数(假设为“foo”)中的那部分 url(西里尔字母)。

使用cflog转储它,我在应用程序日志中看到:

/index.cfm?foo=оÑки-длÑ-зÑениÑ&

...这显然是错误的,因为我需要的是 utf-8 西里尔字母的原始字符串。

我试图将 URIEncoding 参数放入我的 server.xml tomcat http 连接器中,但没有结果:

<Connector port="8888" protocol="HTTP/1.1" 
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />

如何获取 UTF-8 格式的 url 参数?

最佳答案

我自己找到了解决方案。

来源:http://blogs.warwick.ac.uk/kieranshaw/entry/utf-8_internationalisation_with

Apache

Generally you don't need to worry about Apache as it shouldn't be messing with your HMTL or URLs. However, if you are doing some proxying with mod_proxy then you might need to have a think about this. We use mod_proxy to do proxying from Apache through to Tomcat. If you've got encoded characters in URL that you need to convert into some query string for your underlying app then you're going to have a strange little problem.

If you have a URL coming into Apache that looks like this:

http://mydomain/%E4%B8%AD.doc and you have a mod_rewrite/proxy rule like this:

RewriteRule ^/(.*) http://mydomain:8080/filedownload/?filename=$1 [QSA,L,P]

Unfortunately the $1 is going to get mangled during the rewrite. QSA (QueryStringAppend) actually deals with these characters just fine and will send this through untouched, but when you grab a bit of the URL such as my $1 here then the characters get mangled as Apache tries to do some unescaping of its own into ISO-8859-1, but it's UTF-8 not ISO-8859-1 so it doesn't work properly. So, to keep our special characters in UTF-8, we'll escape it back again.

RewriteMap escape int:escape RewriteRule ^/(.*) http://mydomain:8080/filedownload/?filename=${escape:$1} [QSA,L,P]

Take a look at your rewrite logs to see if this is working.

真的很难找。

关于apache - Lucee URI 编码问题(西里尔文),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30273939/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com