在htaccess中重写utf8字符

时间:2014-02-24 08:01:22

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

我正在尝试使用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)init重写引擎请求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)通过/翻译/如何对说盂兰盆应用内\ XC3 \ xa9tit功能于法语盂兰盆-胃口/

     

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/] strip per-dir prefix:/home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/ - >平移/如何对说盂兰盆应用内\ XC3 \ xa9tit功能于法语盂兰盆-胃口/

     

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'翻译/ 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/] strip per-dir prefix:/home/speaksheets.com/public_html/translation/how-to-say-bon-app\xc3\xa9tit-in-french-bon-appetit/ - >平移/如何对说盂兰盆应用内\ XC3 \ xa9tit功能于法语盂兰盆-胃口/

     

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/]重写'翻译/怎么说-bon-app \ xc3 \ xa9tit-in-french-bon-appetit /' - > '的index.php'

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

2 个答案:

答案 0 :(得分:0)

网址不能包含非ASCII字符。必须将所有非ASCII字符转义为%C3%A9之类的转义百分比。 ^(.*)é(.*)永远不应与有效的网址匹配。据我所知,\xYY未定义为Apache中的字节转义序列,因此^(.*)\xc3\xa9(.*)并不意味着您认为它意味着什么。唯一有效的规则是^(.*)%C3%A9(.*),其中包含UTF-8表示“é”的网址转义版本。

答案 1 :(得分:0)

你的规则:

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

很好并且应该有效(也在我的测试中工作)。

但是从重写日志开始,它会出现一些内部规则,首先将其重写为index.php

请确保您的.htaccess中的上述规则非常第一规则