H5ai 中文目录及文件均为乱码404无法下载解决办法

/ 0评 / 2


部署在windows下upupw的运行环境,会有中文目录显示乱码,打开 中文目录提示404的问题。
最新版支持中文目录,但是必须将服务器系统语言改为zh_CN.UTF-8(linux)
这里修改两行代码即可解决:

\_h5ai\private\php\core\class-context.php

public function to_href($path, $trailing_slash = true) {
$rel_path = substr($path, strlen($this->setup->get(‘ROOT_PATH’)));
$parts = explode(‘/’, $rel_path);
$encoded_parts = [];
foreach ($parts as $part) {
if ($part != ”) {
// $encoded_parts[] = rawurlencode($part);
$encoded_parts[] = rawurlencode(mb_convert_encoding($part, "UTF-8", "GBK")); //rawurlencode($part);
}
}
return Util::normalize_path($this->setup->get('ROOT_HREF') . implode('/', $encoded_parts), $trailing_slash);
}
public function to_path($href) {
$rel_href = substr($href, strlen($this->setup->get('ROOT_HREF')));
//return Util::normalize_path($this->setup->get('ROOT_PATH') . '/' . rawurldecode($rel_href));
return Util::normalize_path($this->setup->get('ROOT_PATH') . '/' . iconv( 'UTF-8', 'GBK', rawurldecode($rel_href) ));//rawurldecode($rel_href));
}

找到上面这两个函数,将红色部分修改为上面代码即可。
---------------------------------------------------
关于Nginx下设置部分加密文件夹功能:

设置网站配置文件,以AMH面板为例:/usr/local/nginx/conf/rewrite/down.conf

#禁止访问.ht开头的任何文件
location ~ /\.ht {
deny all;
}
#对secrect目录使用密码认证,并使用Apache .htpasswd文件保存密码
location ^~ /secrect/ {
root /home/wwwroot/www.chenbo.info/web;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
auth_basic "Please input Password:";
auth_basic_user_file /home/wwwroot/www.chenbo.info/web/secrect/.htpasswd;
}

创建/home/wwwroot/down.chenbo.info/web/secrect/目录下.htpasswd文件,并将生成的账号密码添加进去。
密码生成网址:http://tool.oschina.net/htpasswd