Vish
Vish

Reputation: 4492

htaccess rule not working with filesmatch

<FilesMatch ".js">
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^resources/widget/(.*).js$ /resources/widget/$1.js.gz [L]
ForceType text/javascript
Header set Content-Encoding: gzip
</FilesMatch>

This doesnt work with a js file

RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^resources/widget/(.*).js$ /resources/widget/$1.js.gz [L]
ForceType text/javascript
Header set Content-Encoding: gzip

This works with a js file but then it corrupts the rest of the page.

How can I just apply this rule to a js file

Upvotes: 1

Views: 2701

Answers (2)

user562854
user562854

Reputation:

<FilesMatch "\.js$">
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*).js$ $1.js.gz [L]
ForceType text/javascript
Header set Content-Encoding: gzip
</FilesMatch>0

Upvotes: 0

Anush
Anush

Reputation: 1050

RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*).js$ $1.js.gz [L]
ForceType text/javascript
Header set Content-Encoding: gzip

create a htaccess in the js directory and just use this.

Upvotes: 1

Related Questions