2009-02-19 52 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$