【问题标题】:Fix .htaccess error - RewriteCond: NoCase option for non-regex pattern '-f' is not supported修复 .htaccess 错误 - RewriteCond:不支持非正则表达式模式“-f”的 NoCase 选项
【发布时间】:2026-01-14 07:40:01
【问题描述】:

我在error.log中有这个错误是由.htaccess引起的:

AH00665: RewriteCond: NoCase option for non-regex pattern '-f' is not supported and will be ignored.

它说什么?如何解决?

这是.htaccess 文件:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]

根据error.log,第11行是问题的原因:

RewriteCond %{REQUEST_FILENAME}.php -f [NC]

【问题讨论】:

  • 只需从RewriteCond %{REQUEST_FILENAME}.php -f [NC]这一行中删除[NC]
  • 好的,成功了,tnx @anubhava [NC] 做了什么?
  • NC 用于忽略大小写,但不支持-f

标签: php regex apache .htaccess


【解决方案1】:

根据@anubhava 的建议,我从第 11 行删除了[NC],错误消失了。

【讨论】: