【问题标题】:rewrite utf8 characters in htaccess在 htaccess 中重写 utf8 字符
【发布时间】:2014-03-25 18:39:21
【问题描述】:

我正在尝试使用 htaccess 文件将 é 重写为 e。 以下所有规则都失败了。

RewriteRule ^(.*)é(.*) $1e$2 [R,L]
RewriteRule ^(.*)\xc3\xa9(.*) $1e$2 [R,L]
RewriteRule ^(.*)%C3%A9(.*) $1e$2 [R,L]

我有以下调试输出,但是我无法弄清楚它在说什么。

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (2) 请求初始化重写引擎uri /translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) 应用模式 '^( .*)' to uri '/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/'

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) 应用模式 '^( .*)' to uri '/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/'

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (1) 通过 /translation/ how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/ speaksheets.com/public_html/] 添加路径信息后缀:/home/speaksheets.com/public_html/translation -> /home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in -french-bon-appetit/

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/ speaksheets.com/public_html/] 去除每个目录前缀:/home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/ -> 翻译/ how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/ speaksheets.com/public_html/] 将模式 '^index\.php$' 应用于 uri 'translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/'

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/ speaksheets.com/public_html/] 添加路径信息后缀:/home/speaksheets.com/public_html/translation -> /home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in -french-bon-appetit/

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/ speaksheets.com/public_html/] 去除每个目录前缀:/home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/ -> 翻译/ how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (3) [perdir /home/ speaksheets.com/public_html/] 应用模式“。” to uri 'translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/'

197.178.121.8 - - [24/Feb/2014:00:29:35 --0800] [www.speaksheets.com/sid#7ff60b7a0318][rid#7ff60d1edf58/initial] (2) [perdir /home/ speaksheets.com/public_html/] 重写 'translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/' -> '/index.php'

问题是,这条规则有什么问题,RewriteRule ^(.*)\xc3\xa9(.*) $1e$2 [R,L]

【问题讨论】:

    标签: apache .htaccess mod-rewrite utf-8


    【解决方案1】:

    你的规则:

    RewriteRule ^(.*)\xc3\xa9(.*) $1e$2 [R,L]
    

    很好,应该可以工作(在我的测试中也有效)。

    但从重写日志来看,首先在内部将其重写为index.php 时出现了一些规则。

    只需确保上述规则是您的 .htaccess 中的第一条规则

    【讨论】:

    • 你说得对,我已经把它写成了第一条规则,现在它可以正常工作了
    • 您能否提供完整的.htaccess 并删除index.php 表单网址?
    • 评论部分用于讨论问题或发布的答案,而不是用于询问新代码。您应该发布一个包含所有详细信息的新问题。
    【解决方案2】:

    URL 不能包含非 ASCII 字符。所有非 ASCII 字符都必须转义为百分比转义,例如 %C3%A9^(.*)é(.*) 永远不应匹配有效的 URL。据我所知,\xYY 没有被定义为 Apache 中的字节转义序列,所以^(.*)\xc3\xa9(.*) 也不是你认为的意思。唯一有效的规则是 ^(.*)%C3%A9(.*),它包含“é”的 UTF-8 表示的 URL 转义版本。

    【讨论】:

    • "é"在调试日志中表示为\xc3\xa,对规则的匹配有影响吗?
    • 我不确定\xYY 是否有任何特殊意义,但据我所知,它肯定不代表 Apache 或 URL 中的字节转义序列,所以它当然应该'没有你认为的效果。
    猜你喜欢
    • 1970-01-01
    • 2015-01-30
    • 2011-04-06
    • 1970-01-01
    • 2023-03-04
    • 2012-06-16
    • 2012-10-11
    • 2010-11-16
    • 1970-01-01
    相关资源
    最近更新 更多