RewriteCond%{REQUEST_FILENAME}!-f不起作用

问题描述 投票:0回答:1

如果URL中的任何字符均为大写,我编写了以下规则以重定向到小写URL

RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule . https://www.example.com${lc:%{REQUEST_URI}} [R=301,L] 

以上规则可以将https://www.example.com/HelloWorld重定向到https://www.example.com/helloworld

以上规则非常有效,但是我想推迟所有与实际文件URL对应的URL的小写形式。例如,我想将上述规则用于[]

https://www.example.com/ABC.png,如果服务器上实际存在ABC.png文件。

为此,我在下面添加了RewriteCond %{REQUEST_FILENAME} !-f

RewriteMap lc int:tolower
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule . https://www.example.com${lc:%{REQUEST_URI}} [R=301,L]

尽管进行了上述更改,但https://www.example.com/ABC.png已被重定向到ttps://www.example.com/abc.png。这应该很简单,但是不起作用。

如果URL中的任何字符均为大写,则编写以下规则以重定向到小写url RewriteMap lc int:tolower RewriteCond%{REQUEST_URI} [A-Z] RewriteRule。 https://www.example.com$ {lc:...

apache .htaccess mod-rewrite
1个回答
0
投票

已解决。在虚拟主机环境中使用RewriteCond %{REQUEST_FILENAME} !-f时,应将其写为RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f。因此,在这种情况下,总体规则将是

© www.soinside.com 2019 - 2024. All rights reserved.