在http get请求期间,特定的汉字被错误编码

时间:2015-07-03 13:26:14

标签: php mongodb http utf-8 phalcon

当我正在开发的应用程序使用汉字时,我遇到了一个非常奇怪的编码问题;所有汉字字符除了字符"免费"工作得很好。 当我尝试使用这个字符时,mongodb抛出以下异常:

Exception: non-utf8 string: � 

任何其他汉字字符都可以。

我试图删除处理字符串的函数,并将其直接输入到函数处理mongodb但没有成功。 我也试图从各种编码转换角色,但无济于事。

这就是我正在使用的:

谢谢!

处理请求的控制器功能

public function kanjiAction($findKanji = "")
{
    // Really weird issue with the kanji 免 not working

    $findKanji = $this->filter->sanitize($findKanji, 'string');
    $findKanji = mb_substr($findKanji, 0, 1, 'UTF-8');

    $kanjiHash = md5($findKanji);

    // If entry does not exist in cache, create it
    if(!$this->viewCache->exists($kanjiHash)) {

        // Get data from DB
        $kanji = Kanji::findById($findKanji);

        $words = Words::containingKanji($findKanji);

        $showWords = array();

        foreach ($words as $word) {
            foreach ($word->k_ele["keb"] as $key => $value) {
                if(strpos($value, $findKanji) != false) {
                    $showWords[] = (object) array(
                        "word" => $value,
                        "readings" => $word->r_ele["reb"],
                        "meanings" => $word->sense["gloss"]
                    );
                    break;
                }
            }
        }

        // Fetch translations
        $this->view->onTitle = $this->translation->query('onTitle');
        $this->view->kunTitle = $this->translation->query('kunTitle');
        $this->view->radicalTitle = $this->translation->query('radicalTitle');
        $this->view->meaningsTitle = $this->translation->query('meaningsTitle');
        $this->view->strokeCountTitle = $this->translation->query('strokeCountTitle');
        $this->view->jlptTitle = $this->translation->query('jlptTitle');
        $this->view->containsWordsTitle = $this->translation->query('containsWordsTitle');
        $this->view->readingsTitle = $this->translation->query('readingsTitle');
        $this->view->wordsTitle = $this->translation->query('wordsTitle');
        $this->view->notFound = $this->translation->query('notFound');

        // Pass data to view
        $this->view->kanji = $kanji->_id;
        if(isset($kanji->reading["on"]) && count($kanji->reading["on"]) > 0)
            $this->view->onReadings = $kanji->reading["on"];
        if(isset($kanji->reading["kun"]) && count($kanji->reading["kun"]) > 0)
            $this->view->kunReadings = $kanji->reading["kun"];
        if(isset($kanji->radicals))
            $this->view->radicals = $kanji->radicals;
        if(isset($kanji->attributes['jlpt']))
            $this->view->jlpt = $kanji->attributes['jlpt'];
        if(isset($kanji->attributes['stroke_count']))
            $this->view->strokeCount = $kanji->attributes['stroke_count'];
        if(isset($kanji->meaning))
            $this->view->meanings = $kanji->meaning;
        if(count($showWords) > 0) 
            $this->view->words = $showWords;

        $this->view->kanjiHash = $kanjiHash;
    } else {
        $this->view->kanjiHash = $kanjiHash;
    }
}

请求非工作汉字的标头:

GET /view/kanji/%E5%85%8D HTTP/1.1
Host: localhost
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: sv-SE,sv;q=0.8,en-US;q=0.6,en;q=0.4

非工作汉字的回复标题:

HTTP/1.1 200 OK
Date: Fri, 03 Jul 2015 13:04:05 GMT
Server: Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8
X-Powered-By: PHP/5.6.8
Content-Length: 29
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8

请求工作汉字的标题:

GET /view/kanji/%E5%A8%A9 HTTP/1.1
Host: localhost
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: sv-SE,sv;q=0.8,en-US;q=0.6,en;q=0.4

工作汉字的响应标题:

HTTP/1.1 200 OK
Date: Fri, 03 Jul 2015 13:16:20 GMT
Server: Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8
X-Powered-By: PHP/5.6.8
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

编辑:

免费的堆栈跟踪:

#0 [internal function]: MongoCursor->rewind()
#1 [internal function]: Phalcon\Mvc\Collection::_getResultset(Array, Object(Purple\Model\Kanji), Object(MongoDB), true)
#2 [internal function]: Phalcon\Mvc\Collection::findFirst(Array)
#3 E:\xampp\htdocs\app\Purple\Controller\ViewController.php(33): Phalcon\Mvc\Collection::findById('\xE5')
#4 [internal function]: Purple\Controller\ViewController->kanjiAction('\xE5')
#5 [internal function]: Phalcon\Dispatcher->dispatch()
#6 E:\xampp\htdocs\public\index.php(98): Phalcon\Mvc\Application->handle()
#7 {main}

编辑2:

[Mon Jul 06 18:05:59.294298 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] add path info postfix: E:/xampp/htdocs/view -> E:/xampp/htdocs/view/kanji/\xe5\x85\x8d
[Mon Jul 06 18:05:59.294798 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] strip per-dir prefix: E:/xampp/htdocs/view/kanji/\xe5\x85\x8d -> view/kanji/\xe5\x85\x8d
[Mon Jul 06 18:05:59.294798 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] applying pattern '^$' to uri 'view/kanji/\xe5\x85\x8d'
[Mon Jul 06 18:05:59.294798 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] add path info postfix: E:/xampp/htdocs/view -> E:/xampp/htdocs/view/kanji/\xe5\x85\x8d
[Mon Jul 06 18:05:59.294798 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] strip per-dir prefix: E:/xampp/htdocs/view/kanji/\xe5\x85\x8d -> view/kanji/\xe5\x85\x8d
[Mon Jul 06 18:05:59.294798 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] applying pattern '(.*)' to uri 'view/kanji/\xe5\x85\x8d'
[Mon Jul 06 18:05:59.294798 2015] [rewrite:trace2] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] rewrite 'view/kanji/\xe5\x85\x8d' -> 'public/view/kanji/\xe5'
[Mon Jul 06 18:05:59.294798 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] add per-dir prefix: public/view/kanji/\xe5 -> E:/xampp/htdocs/public/view/kanji/\xe5
[Mon Jul 06 18:05:59.294798 2015] [rewrite:trace2] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] strip document_root prefix: E:/xampp/htdocs/public/view/kanji/\xe5 -> /public/view/kanji/\xe5
[Mon Jul 06 18:05:59.294798 2015] [rewrite:trace1] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f045c0/initial] [perdir E:/xampp/htdocs/] internal redirect with /public/view/kanji/\xe5 [INTERNAL REDIRECT]
[Mon Jul 06 18:05:59.296799 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f06278/initial/redir#1] [perdir E:/xampp/htdocs/public/] add path info postfix: E:/xampp/htdocs/public/view -> E:/xampp/htdocs/public/view/kanji/\xe5
[Mon Jul 06 18:05:59.296799 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f06278/initial/redir#1] [perdir E:/xampp/htdocs/public/] strip per-dir prefix: E:/xampp/htdocs/public/view/kanji/\xe5 -> view/kanji/\xe5
[Mon Jul 06 18:05:59.317801 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f06278/initial/redir#1] [perdir E:/xampp/htdocs/public/] applying pattern '^(.*)$' to uri 'view/kanji/\xe5'
[Mon Jul 06 18:05:59.318301 2015] [rewrite:trace2] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f06278/initial/redir#1] [perdir E:/xampp/htdocs/public/] rewrite 'view/kanji/\xe5' -> 'index.php?_url=/view/kanji/\xe5'
[Mon Jul 06 18:05:59.318301 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f06278/initial/redir#1] split uri=index.php?_url=/view/kanji/\xe5 -> uri=index.php, args=_url=/view/kanji/\xe5
[Mon Jul 06 18:05:59.318301 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f06278/initial/redir#1] [perdir E:/xampp/htdocs/public/] add per-dir prefix: index.php -> E:/xampp/htdocs/public/index.php
[Mon Jul 06 18:05:59.318301 2015] [rewrite:trace2] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f06278/initial/redir#1] [perdir E:/xampp/htdocs/public/] strip document_root prefix: E:/xampp/htdocs/public/index.php -> /public/index.php
[Mon Jul 06 18:05:59.318301 2015] [rewrite:trace1] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f06278/initial/redir#1] [perdir E:/xampp/htdocs/public/] internal redirect with /public/index.php [INTERNAL REDIRECT]
[Mon Jul 06 18:05:59.318301 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f0d7d8/initial/redir#2] [perdir E:/xampp/htdocs/public/] strip per-dir prefix: E:/xampp/htdocs/public/index.php -> index.php
[Mon Jul 06 18:05:59.318301 2015] [rewrite:trace3] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f0d7d8/initial/redir#2] [perdir E:/xampp/htdocs/public/] applying pattern '^(.*)$' to uri 'index.php'
[Mon Jul 06 18:05:59.318801 2015] [rewrite:trace1] [pid 5728:tid 2180] mod_rewrite.c(475): [client 127.0.0.1:52741] 127.0.0.1 - - [localhost/sid#3dac08][rid#3f0d7d8/initial/redir#2] [perdir E:/xampp/htdocs/public/] pass through E:/xampp/htdocs/public/index.php

编辑3:

[Tue Jul 07 01:25:18.844429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] add path info postfix: E:/xampp/htdocs/view -> E:/xampp/htdocs/view/kanji/\xe5\x85\x8d
[Tue Jul 07 01:25:18.844429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] strip per-dir prefix: E:/xampp/htdocs/view/kanji/\xe5\x85\x8d -> view/kanji/\xe5\x85\x8d
[Tue Jul 07 01:25:18.844429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] applying pattern '^$' to uri 'view/kanji/\xe5\x85\x8d'
[Tue Jul 07 01:25:18.844429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] add path info postfix: E:/xampp/htdocs/view -> E:/xampp/htdocs/view/kanji/\xe5\x85\x8d
[Tue Jul 07 01:25:18.844429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] strip per-dir prefix: E:/xampp/htdocs/view/kanji/\xe5\x85\x8d -> view/kanji/\xe5\x85\x8d
[Tue Jul 07 01:25:18.844929 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] applying pattern '(.*)' to uri 'view/kanji/\xe5\x85\x8d'
[Tue Jul 07 01:25:18.844929 2015] [rewrite:trace2] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] rewrite 'view/kanji/\xe5\x85\x8d' -> 'public/view%2fkanji%2f%e5'
[Tue Jul 07 01:25:18.844929 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] add per-dir prefix: public/view%2fkanji%2f%e5 -> E:/xampp/htdocs/public/view%2fkanji%2f%e5
[Tue Jul 07 01:25:18.844929 2015] [rewrite:trace2] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] strip document_root prefix: E:/xampp/htdocs/public/view%2fkanji%2f%e5 -> /public/view%2fkanji%2f%e5
[Tue Jul 07 01:25:18.844929 2015] [rewrite:trace1] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f240c8/initial] [perdir E:/xampp/htdocs/] internal redirect with /public/view%2fkanji%2f%e5 [INTERNAL REDIRECT]
[Tue Jul 07 01:25:18.849429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f25e28/initial/redir#1] [perdir E:/xampp/htdocs/public/] add path info postfix: E:/xampp/htdocs/public/view -> E:/xampp/htdocs/public/view/kanji/\xe5
[Tue Jul 07 01:25:18.849429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f25e28/initial/redir#1] [perdir E:/xampp/htdocs/public/] strip per-dir prefix: E:/xampp/htdocs/public/view/kanji/\xe5 -> view/kanji/\xe5
[Tue Jul 07 01:25:18.849429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f25e28/initial/redir#1] [perdir E:/xampp/htdocs/public/] applying pattern '^(.*)$' to uri 'view/kanji/\xe5'
[Tue Jul 07 01:25:18.849429 2015] [rewrite:trace2] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f25e28/initial/redir#1] [perdir E:/xampp/htdocs/public/] rewrite 'view/kanji/\xe5' -> 'index.php?_url=/view%2fkanji%2f%e5'
[Tue Jul 07 01:25:18.849429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f25e28/initial/redir#1] split uri=index.php?_url=/view%2fkanji%2f%e5 -> uri=index.php, args=_url=/view%2fkanji%2f%e5
[Tue Jul 07 01:25:18.849429 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f25e28/initial/redir#1] [perdir E:/xampp/htdocs/public/] add per-dir prefix: index.php -> E:/xampp/htdocs/public/index.php
[Tue Jul 07 01:25:18.849429 2015] [rewrite:trace2] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f25e28/initial/redir#1] [perdir E:/xampp/htdocs/public/] strip document_root prefix: E:/xampp/htdocs/public/index.php -> /public/index.php
[Tue Jul 07 01:25:18.849429 2015] [rewrite:trace1] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f25e28/initial/redir#1] [perdir E:/xampp/htdocs/public/] internal redirect with /public/index.php [INTERNAL REDIRECT]
[Tue Jul 07 01:25:18.849930 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f2d448/initial/redir#2] [perdir E:/xampp/htdocs/public/] strip per-dir prefix: E:/xampp/htdocs/public/index.php -> index.php
[Tue Jul 07 01:25:18.849930 2015] [rewrite:trace3] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f2d448/initial/redir#2] [perdir E:/xampp/htdocs/public/] applying pattern '^(.*)$' to uri 'index.php'
[Tue Jul 07 01:25:18.850430 2015] [rewrite:trace1] [pid 7480:tid 2176] mod_rewrite.c(475): [client 127.0.0.1:63967] 127.0.0.1 - - [localhost/sid#5fac08][rid#3f2d448/initial/redir#2] [perdir E:/xampp/htdocs/public/] pass through E:/xampp/htdocs/public/index.php

1 个答案:

答案 0 :(得分:3)

在堆栈跟踪中,似乎某些内容在$findKanji到达控制器之前被剥离掉了。而不是代表免费的三个字节,只有kanjiAction调用中的第一个。

失败的另一个汉字也包含一个0x85个字节,所以我想知道在你点击控制器之前是否有东西在它到达字节0x85时剥离所有字节。

所以现在你需要看看在你的参数到达你的控制器之前可能会干扰你的参数。您是否有dispatch:beforeDispatchLoop或任何dispatch事件附加的事件监听器? (如果是的话,那是什么?)

我会注意到我刚刚从头开始制作一个phalcon应用程序(按照教程)看到我得到的堆栈跟踪,我得到了堆栈跟踪:

Exception: Because I can
 File=/var/www/tutorial/app/controllers/ViewController.php
 Line=15
#0 [internal function]: ViewController->kanjiAction('???')
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 /var/www/tutorial/public/index.php(39): Phalcon\Mvc\Application->handle()
#3 {main}

请注意传递给kanjiAction的三个字符:如果我点击了网址/view/kanji/%E5,我只能获得一个字符。

这是一个简化的控制器,只是为了给出一个堆栈跟踪:

<?php

use Phalcon\Mvc\Controller;

class ViewController extends Controller
{

    public function indexAction()
    {
    }

    public function kanjiAction($findKanji = "")
    {
        var_dump($findKanji);
        throw new Exception('Because I can');
    }
}

这是使用Phalcon 2.0.1。所以我们知道一个vanilla phalcon应用程序将所有三个字节传递给处理程序,至少在我的ubuntu和Apache 2.2的设置上。

看看我的设置(显然有效)和你的设置之间的区别,我想知道这些差异是否与Windows上的Apache重写规则有关。那么让我们在重写过程中调试调试。既然你有Apache 2.4,就可以通过这个指令来完成:

LogLevel alert rewrite:trace3

进入服务器配置文件中的<VirtualHost>部分。

执行此操作后,使用apache日志中包含[rewrite:的行更新答案,这些行是在您尝试访问其中一个错误汉字时生成的。

编辑:现在您已经包含了这些信息,我想我已经解决了。

我不知道为什么你会看到你的问题。我将分别尝试重现它,以便我可以使用apache提交错误(虽然我可能无法直到我得到一个Windows框),但在此期间我认为我有一个修复。

首先,在服务器配置文件的<VirtualHost>部分添加此指令:

AllowEncodedSlashes On

然后,假设您已在Phalcon教程中设置了.htaccess个文件,请将B选项添加到顶级目录的RewriteRule文件中的第二个.htaccess ,以便该行看起来像:

RewriteRule  (.*) public/$1 [B,L]

然后还将B标记添加到RewriteRule目录中.htaccess文件中的public/行,以便该行变为:

RewriteRule ^(.*)$ index.php?_url=/$1 [B,QSA,L]

第二次更改可能没有必要;由于我没有确切问题的系统,我无法检查。

仍然没有运气,但让我们再试一次:将(.*)变成((?s).*),以便之前修改的行读取:

RewriteRule  ((?s).*) public/$1 [B,L]

RewriteRule ^((?s).*)$ index.php?_url=/$1 [B,QSA,L]

假设这是有效的,其背后的推理是奇怪的。

显然,字符0x85是Unicode中的“下一行”字符,可以被PCRE(Apache的重写功能的正则表达式引擎)视为换行符as detailed here。编译PCRE的正常方法是仅将字符10视为换行符(\ n),但可以编译PCRE以将更多字符视为换行符。

当字符是“换行符”字符时,正则表达式字符.将不匹配,除非s正则表达式选项处于活动状态。 (?s)位使该选项处于活动状态。

如果此方法有效,您可以删除B上的RewriteRules选项,并从AllowEncodedSlashes中删除<VirtualHost>指令。

您使用的是本地编译的apache二进制文件,还是从官方版本获得了一个?因为如果你有一个来自官方的地方,你应该抱怨他们用这个奇怪的选项编译PCRE会浪费你的周末。