apache - 模组重写 : apply to all js and css files except

标签 apache .htaccess mod-rewrite url-rewriting

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

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

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

我需要添加条件来表示:

适用于除 jquery.js、prototype.js 等之外的所有内容。

最佳答案

试试这个

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,并且可以在硬盘上找到。

关于apache - 模组重写 : apply to all js and css files except ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/566872/

相关文章:

apache - PHP : How to code . htaccess 使其无需编辑即可在本地主机和在线上运行

.htaccess - 当某些查询字符串存在时允许访问,否则拒绝

php - Digital Ocean 上 WordPress 的 htaccess 文件持续损坏

php - 重写一个链接,mod_rewrite

java - 如何用 Java 进行 FTP

python - 如何在一台 Apache 服务器上部署多个 Python 2 和 3 Django 项目?

c++ - 为 C++ 应用程序启用核心转储(通过 apache -> Perl -> C++ 调用)

php - 如何在 Codeigniter 中重定向和删除 index.php

.htaccess 通配符重定向修复

html - Apache(.htaccess 和 mod_rewrite)url 重写/重定向不起作用 :404 page not found error