2009-02-19 48 views
3
之外的所有js和css文件

我需要对所有javascript和CSS文件应用minify操作,但我指出的文件除外。Mod重写:适用于除

我有一个适用于所有文件(CSS和JS)这一条件和规则:

RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^(.*\.)(js|css)$ minify.php?q=$1$2 [L,NC] 

我需要添加的条件说:

适用于所有情况除外:的jquery.js ,prototype.js中,等等。

回答

8

试试这个

RewriteCond %{REQUEST_FILENAME} !^.*jquery.js$ 
RewriteCond %{REQUEST_FILENAME} !^.*prototype.js$ 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule ^(.*\.)(js|css)$ minify.php?q=$1$2 [L,NC] 

这里的关键是雷杰的反转x使用“!” (感叹号)说,文件名不是jquery.js而不是prototype.js,它可以在硬盘上找到。

0

您可以使用RewriteCond来指定应该应用RewriteRule的条件。所以,在前面加上这几行.htaccess

RewriteCond %{REQUEST_FILENAME} !jquery.js 
RewriteCond %{REQUEST_FILENAME} !prototype.js 
0

非常感谢你为这个!近一个月来,我一直在为这个问题寻找答案。我的问题是如何重写一些文件到https和其余的http,但我能够修改上面,使其工作。这是我的一段代码。 (我在网站上的真实.htaccess中有很多文件。)

################################################################# 
# To only change certain files from http to https, the rest from 
# https to http. Absolute links are set up throughout the site, 
# but if a visitor for some reason edits the URL in the address 
# bar, the URL will change back to the proper format. 

Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{HTTP_HOST} ^alvingolf\.com$ [NC] 
RewriteCond %{HTTPS} on 
RewriteCond %{SERVER_PORT} ^443$ 
RewriteCond %{REQUEST_FILENAME} !^.*contact-us.html$ 
RewriteCond %{REQUEST_FILENAME} !^.*register-for-tournaments.html$ 
RewriteCond %{REQUEST_FILENAME} !^.*form.htm$