htaccess的mod-rewrite正则表达式不匹配文件名文件名、不匹配、正则表达式、htaccess

2023-09-02 10:02:40 作者:烂到尾的感情

我用下面的.htaccess配置指令(重定向所有非文件名请求到同一个PHP文件):

I am using the following .htaccess configuration directives (to redirect all non filename requests to a single PHP file):

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]或把(我)在beggining。 NC选项不能在所有的Apache2安装工作(各种版本)和(我)没有任何影响。

How can I make the above regex case insensitive? I have tried [L,NC] or placing (?i) at the beggining. NC option doesn't work on all Apache2 installations (various versions) and (?i) has no effect.

我怎样才能让一个正则表达式这将的没有的匹配URLS看起来像一个文件名,有2个和4个字符之间的延伸?

How can I make a regex which will not match URLS which look like a filename with an extension between 2 and 4 characters?

感谢您的帮助。

推荐答案

试试这个:

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

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

But if you want to redirect requests to files that does not exists on your server, it is better to use :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . mod_rewrite_redirector.php [L]