apache Mod Rewrite:适用于所有 js 和 css 文件,除了
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/566872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mod Rewrite: apply to all js and css files except
提问by Leandro Ardissone
I need to apply a minify actions to all the javascript and CSS files, except the ones I indicate.
我需要对所有 javascript 和 CSS 文件应用 minify 操作,除了我指出的那些。
I have this condition and rule that applies to all the files (css and js):
我有适用于所有文件(css 和 js)的条件和规则:
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.)(js|css)$ minify.php?q= [L,NC]
I need to add the conditions to say:
我需要添加条件说:
Apply to all except: jquery.js, prototype.js, etc..
适用于所有除了:jquery.js、prototype.js 等。
回答by Nick Berardi
Try this
尝试这个
RewriteCond %{REQUEST_FILENAME} !^.*jquery.js$
RewriteCond %{REQUEST_FILENAME} !^.*prototype.js$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.)(js|css)$ minify.php?q= [L,NC]
The key to this is the inversion of the regex using the "!" (exclamation point) to say the file name is not jquery.js and not prototype.js and it can be found on the hard drive.
关键是使用“!”反转正则表达式。(感叹号)说文件名不是jquery.js也不是prototype.js,可以在硬盘上找到。
回答by Bouke
You can use RewriteCondto specify on which conditions the RewriteRuleshould be applied. So prepend these lines to your .htaccess:
您可以使用RewriteCond来指定RewriteRule应在哪些条件下应用。因此,将这些行添加到您的.htaccess:
RewriteCond %{REQUEST_FILENAME} !jquery.js
RewriteCond %{REQUEST_FILENAME} !prototype.js
回答by Bouke
Thank you so much for this! I've been searching for this answer to my problem for almost a month. My problem was how to rewrite some files to https and the rest to http, but I was able to modify above to make it work. Here's a chunk of my code. (I have a lot more files in the real .htaccess on the site.)
非常感谢你做的这些!近一个月以来,我一直在寻找这个问题的答案。我的问题是如何将一些文件重写为 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$

