用户
 找回密码
 入住 CI 中国社区
搜索
12
返回列表 发新帖
楼主: stalkerru
收起左侧

包含某些中文字符的url会忽略.htaccess里的rewrite规则导致404

[复制链接]
发表于 2017-2-8 12:25:23 | 显示全部楼层
stalkerru 发表于 2017-2-7 21:10
url rewrite的log怎么打开?在apache的httpd.conf里吗

是的,你可以参考这个 http://httpd.apache.org/docs/current/mod/mod_rewrite.html 手册。
 楼主| 发表于 2017-2-10 15:50:52 | 显示全部楼层
Hex 发表于 2017-2-8 12:25
是的,你可以参考这个 http://httpd.apache.org/docs/current/mod/mod_rewrite.html 手册。

安全的“安”字:
[Fri Feb 10 15:31:25.720286 2017] [rewrite:trace3] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#260a0c8/initial] [perdir D:/xampp/htdocs/] add path info postfix: D:/xampp/htdocs/attachment -> D:/xampp/htdocs/attachment/download/\xe5\xae\x89
[Fri Feb 10 15:31:25.720286 2017] [rewrite:trace3] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#260a0c8/initial] [perdir D:/xampp/htdocs/] strip per-dir prefix: D:/xampp/htdocs/attachment/download/\xe5\xae\x89 -> attachment/download/\xe5\xae\x89
[Fri Feb 10 15:31:25.720286 2017] [rewrite:trace3] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#260a0c8/initial] [perdir D:/xampp/htdocs/] applying pattern '^(.*)$' to uri 'attachment/download/\xe5\xae\x89'
[Fri Feb 10 15:31:25.720286 2017] [rewrite:trace2] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#260a0c8/initial] [perdir D:/xampp/htdocs/] rewrite 'attachment/download/\xe5\xae\x89' -> 'index.php?/attachment/download/\xe5\xae\x89'
[Fri Feb 10 15:31:25.720286 2017] [rewrite:trace3] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#260a0c8/initial] split uri=index.php?/attachment/download/\xe5\xae\x89 -> uri=index.php, args=/attachment/download/\xe5\xae\x89
[Fri Feb 10 15:31:25.720286 2017] [rewrite:trace3] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#260a0c8/initial] [perdir D:/xampp/htdocs/] add per-dir prefix: index.php -> D:/xampp/htdocs/index.php
[Fri Feb 10 15:31:25.720286 2017] [rewrite:trace2] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#260a0c8/initial] [perdir D:/xampp/htdocs/] trying to replace prefix D:/xampp/htdocs/ with /
[Fri Feb 10 15:31:25.721286 2017] [rewrite:trace1] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#260a0c8/initial] [perdir D:/xampp/htdocs/] internal redirect with /index.php [INTERNAL REDIRECT]
[Fri Feb 10 15:31:25.721286 2017] [rewrite:trace3] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#9db11a0/initial/redir#1] [perdir D:/xampp/htdocs/] strip per-dir prefix: D:/xampp/htdocs/index.php -> index.php
[Fri Feb 10 15:31:25.721286 2017] [rewrite:trace3] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#9db11a0/initial/redir#1] [perdir D:/xampp/htdocs/] applying pattern '^(.*)$' to uri 'index.php'
[Fri Feb 10 15:31:25.721286 2017] [rewrite:trace1] [pid 2628:tid 1640] mod_rewrite.c(477): [client 192.168.1.9:51233] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#9db11a0/initial/redir#1] [perdir D:/xampp/htdocs/] pass through D:/xampp/htdocs/index.php

安全的“全”字:
[Fri Feb 10 15:32:27.507820 2017] [rewrite:trace3] [pid 2628:tid 1652] mod_rewrite.c(477): [client 192.168.1.9:51245] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#34350d8/initial] [perdir D:/xampp/htdocs/] add path info postfix: D:/xampp/htdocs/attachment -> D:/xampp/htdocs/attachment/download/\xe5\x85\xa8
[Fri Feb 10 15:32:27.507820 2017] [rewrite:trace3] [pid 2628:tid 1652] mod_rewrite.c(477): [client 192.168.1.9:51245] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#34350d8/initial] [perdir D:/xampp/htdocs/] strip per-dir prefix: D:/xampp/htdocs/attachment/download/\xe5\x85\xa8 -> attachment/download/\xe5\x85\xa8
[Fri Feb 10 15:32:27.507820 2017] [rewrite:trace3] [pid 2628:tid 1652] mod_rewrite.c(477): [client 192.168.1.9:51245] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#34350d8/initial] [perdir D:/xampp/htdocs/] applying pattern '^(.*)$' to uri 'attachment/download/\xe5\x85\xa8'
[Fri Feb 10 15:32:27.507820 2017] [rewrite:trace1] [pid 2628:tid 1652] mod_rewrite.c(477): [client 192.168.1.9:51245] 192.168.1.9 - - [192.168.1.9/sid#6fac40][rid#34350d8/initial] [perdir D:/xampp/htdocs/] pass through D:/xampp/htdocs/attachment



 楼主| 发表于 2017-2-10 15:57:22 | 显示全部楼层
accesslog里的情况也是

安全的“安”字:

192.168.1.9 - - [10/Feb/2017:15:27:20 +0800] "GET /attachment/download/%E5%AE%89 HTTP/1.1" 200


安全的“全”字:

192.168.1.9 - - [10/Feb/2017:15:27:34 +0800] "GET /attachment/download/%E5%85%A8 HTTP/1.1" 404
发表于 2017-2-10 17:12:23 | 显示全部楼层
stalkerru 发表于 2017-2-10 15:57
accesslog里的情况也是

安全的“安”字:

还是 URL 没有编码的问题,你把中文先做一个 urlencode() 然后再拼到 URL 中,不要做 base64 这都不是标准做法,URL 除了英文以外,其他字符必须编码,这是协议规定。
 楼主| 发表于 2017-2-12 01:15:34 | 显示全部楼层
Hex 发表于 2017-2-10 17:12
还是 URL 没有编码的问题,你把中文先做一个 urlencode() 然后再拼到 URL 中,不要做 base64 这都不是标准 ...

试过了   提前用php编码跟apache自动编码生成的链接是一样的
发表于 2017-2-14 10:35:17 | 显示全部楼层
stalkerru 发表于 2017-2-12 01:15
试过了   提前用php编码跟apache自动编码生成的链接是一样的

那就不建议把中文放到 URL 中了,我一般都是把中文放到参数中的,没有任何问题。你这个问题我也说不好怎么解决。
发表于 2017-4-5 15:42:25 | 显示全部楼层
stalkerru 发表于 2017-2-7 14:02
我现在很无奈地用base64对中文进行编码后传递了   但还是很想知道这是什么原因导致的
...

楼主找到原因了吗,本人也遇到同样的问题
发表于 2018-1-26 19:22:46 | 显示全部楼层
受楼主启发,我把.htaccess文件里的路由规则改为 RewriteRule ^([\s\S]*)$ index.php/$1 [L] 即可!我是升级了apache版本后才出现这个问题
发表于 2018-1-26 19:24:33 | 显示全部楼层
gqh49868 发表于 2017-4-5 15:42
**** 作者被禁止或删除 内容自动屏蔽 ****

18楼

本版积分规则