wordpress - WordPress 中带有 URL 编码字符的图像上传文件夹返回 404
问题描述
我的 WordPress 上传文件夹中有很多图片。这些图像中的大多数显示都很好。但是,当我尝试通过网络浏览器访问它们时,任何文件名中包含 URL 编码字符(例如,%22
而不是)的图像都会返回 404。"
我已经通过 FTP 连接、下载有问题的图像之一并在我的计算机上打开它来验证这些图像文件是否存在于服务器上。
我想这可能是一个.htaccess
问题,但.htaccess
对我来说是不可思议的。这.htaccess
是我网站的根目录:
# BEGIN rlrssslReallySimpleSSL rsssl_version[3.3.5]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Wordfence WAF
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
# END Wordfence WAF
这是.htaccess
我/wp-content/uploads/
文件夹中的文件:
# BEGIN Wordfence code execution protection
<IfModule mod_php5.c>
php_flag engine 0
</IfModule>
<IfModule mod_php7.c>
php_flag engine 0
</IfModule>
<IfModule mod_php.c>
php_flag engine 0
</IfModule>
AddHandler cgi-script .php .phtml .php3 .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
# END Wordfence code execution protection
.htaccess
我的图像路径上没有其他文件。我觉得我快疯了,但我很可能错过了一些明显的东西。
解决方案
这似乎是来自客户端的初始 HTTP 请求的 URL 编码问题,与您的.htaccess
文件无关。如果实际的文件名包含%22
,则需要在请求中将 URL 编码为%2522
(即%
in%22
也需要进行 % 编码),否则,它将寻找包含 的文件"
,而不是%22
(当请求的 URL 被解码时) .
这不是您的.htaccess
文件的问题,尽管您可以在.htaccess
(手动对这些请求进行 URL 编码)的帮助下解决此问题,但前提是您无法“修复”HTML 源中请求的 URL。从源头修复这些 URL 将是首选解决方案。
不用说,首先避免文件名中的特殊字符(即清理上传的文件名)将是首选。双引号 ( "
) 是 Windows 操作系统文件名中的无效字符,所以这可能就是为什么它在文件名中保持 % 编码?但除此之外, %-encoded 字符在filenames中没有位置,因为这是一个URL编码方案。
推荐阅读
- python - Python venv 返回错误消息。如何在windows上创建一个venv
- javascript - 带有特殊字符的字符串无法在 innerHTML 中正确呈现
- r - ggplot2中离子轴标签中的上标
- javascript - 如何在箭头函数中进行条件渲染?
- anylogic - 使用数据库中的动态事件和日期的自定义流程图中的 Rack Pick
- django - 如何通过beautifulsoup中的.find方法从嵌套标签中获取价值
- azure-cosmosdb - 安装后 ERR_CONNECTION_REFUSED 上的 Azure Cosmos DB
- javascript - 用于导出字段内容的带有 javascript 的 HTML 表单 - 无法阻止表单在按钮单击时重置
- docker - 带有 WSL2 的 Docker 桌面无法启动
- java - 如何在 Java 中使子类不可变?