【发布时间】:2021-06-30 03:08:24
【问题描述】:
我的 WordPress 上传文件夹中有很多图片。这些图像中的大多数显示都很好。但是,当我尝试通过 Web 浏览器访问它们时,任何文件名中包含 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
这是我的/wp-content/uploads/ 文件夹中的.htaccess 文件:
# 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 文件。我感觉自己快疯了,但我很可能遗漏了一些明显的东西。
【问题讨论】:
-
您使用什么 URL 来请求这些图片?如果实际文件名包含
%22,则需要在请求中将URL 编码为%2522,否则,它将查找包含"的文件,而不是%22(当请求的URL 被解码时)。这不是.htaccess问题,但如果您无法“修复” HTML 源代码中请求的 URL(这将是更好的解决方案),则可以使用.htaccess解决。 -
@MrWhite 这似乎正是问题所在!非常感谢!
-
不客气。我在下面添加了我的评论(带有一些附加信息)作为“答案”。如果您可以通过单击投票箭头下方左侧答案旁边的勾号/复选标记将其标记为“已接受”,将不胜感激(帮助其他用户并从未回答的问题队列中删除问题)。您还可以为您认为有帮助的答案投票。谢谢。 :)
标签: wordpress .htaccess upload http-status-code-404 urlencode