【发布时间】:2021-04-20 15:20:25
【问题描述】:
我在下载包含“ñ”或“Ñ”等特殊字符的文件时遇到问题。
我将 rawurlencode() 应用于每个文件名。但是当我点击路由时,apache 正在重写我的 url。
<td>
<a href="{{asset("storage/" . rawurlencode($fyi->file))}}" target="_blank">{{$fyi->name}}</a></td>
当我检查 a 标签中的 href 时,我得到了正确的 URL 编码路由,如下图所示。
但是当我点击链接时,编码丢失了
missing encoded after hitting the link
这里是我的 apache 配置
<VirtualHost *:80>
ServerName xxx.com
ServerAlias xxx.con
DocumentRoot /home/dev/xxx.com/public
AllowEncodedSlashes On
<Directory /home/dev/xxx.com/public>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/xxx.com-error.log
CustomLog ${APACHE_LOG_DIR}/xxx.com-access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =xxx.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [QSA,L]
</VirtualHost>
【问题讨论】:
-
这只是浏览器向您很好地显示它。检查浏览器开发工具或服务器日志中的网络选项卡,您会看到它实际上已编码。 i.stack.imgur.com/hCm7D.png
-
哦,你是对的,好吧,所以这不是问题,所以我必须打开一个新问题,看看为什么它没有创建每个有“ñ”的文件??
-
当您使用非 ASCII 字符(例如
ñ)时,通过 HTTP 服务器链接原始文件会变得很容易。所涉及的层(文件系统、Apache、PHP...)在编码上并不总是一致。