1

我正在使用以下 .htaccess 配置指令(将所有非文件名请求重定向到单个 PHP 文件):

RewriteEngine on
Options +FollowSymLinks
RewriteBase /

RewriteRule !(\.ttf|\.eot|\.woff|\.xpi|\.xml|\.txt|\.air|\.exe|\.zip|\.pdf|\.ico|\.gif|\.jpg|\.png|\.jpeg|\.js|\.swf|\.css|\.php|\.html)$ mod_rewrite_redirector.php [L]

如何使上述正则表达式不区分大小写?我尝试过 [L,NC] 或将 (?i) 放在开头。NC 选项不适用于所有 Apache2 安装(各种版本)并且 (?i) 无效。

如何制作一个匹配看起来像扩展名在 2 到 4 个字符之间的文件名的 URL 的正则表达式?

感谢您的帮助。

4

1 回答 1

1

试试这个 :

RewriteRule !\.[a-zA-Z0-9]{2,4}$ mod_rewrite_redirector.php [L]

但是,如果要将请求重定向到服务器上不存在的文件,最好使用:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . mod_rewrite_redirector.php [L]
于 2012-09-13T14:24:52.310 回答