Mod Rewrite: applies to all js and css files except

I need to apply minimization measures to all javascript and CSS files except the ones I specify.

I have this condition and rule that applies to all files (css and js):

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

I need to add conditions to say:

Apply to all but jquery.js, prototype.js, etc.

+3
source share
3 answers

try it

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

The key to this is regular expression inversion using "!" (exclamation mark) to say that the file name is not jquery.js, not prototype.js, and it can be found on the hard drive.

+8
source

RewriteCond, , RewriteRule. .htaccess:

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

Thank you so much for this! I have been looking for this answer to my problem for almost a month. My problem was how to overwrite some files on https and the rest on http, but I was able to change above to make it work. Here is a piece of my code. (I have a lot more real .htaccess files on the site.)

#################################################################
# 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$
0
source

Source: https://habr.com/ru/post/1703523/


All Articles