3

我需要对所有 javascript 和 CSS 文件应用缩小操作,但我指出的文件除外。

我有适用于所有文件(css 和 js)的条件和规则:

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

我需要添加条件说:

适用于所有除:jquery.js、prototype.js 等。

4

3 回答 3

9

试试这个

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

关键是使用“!”反转正则表达式 (感叹号)说文件名不是 jquery.js 也不是prototype.js 并且可以在硬盘上找到。

于 2009-02-19T19:56:43.030 回答
1

您可以使用RewriteCond指定RewriteRule应在哪些条件下应用。因此,将这些行添加到您的.htaccess

RewriteCond %{REQUEST_FILENAME} !jquery.js
RewriteCond %{REQUEST_FILENAME} !prototype.js
于 2009-02-19T19:57:36.757 回答
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$
于 2009-06-01T15:50:07.543 回答