htaccess的mod-rewrite正则表达式不匹配文件名 [英] .htaccess mod rewrite regex to not match file names

查看:224
本文介绍了htaccess的mod-rewrite正则表达式不匹配文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的.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]

这篇关于htaccess的mod-rewrite正则表达式不匹配文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆