Problem with redirecting JS to compressed copy

Using mod_rewrite to handle various content issues

Problem with redirecting JS to compressed copy

Postby init2null » Tue Mar 03, 2009 2:11 pm

Hello all,

I'm trying to implement a poor man's substitute to mod_gzip since my provider refuses to turn it on, and I'm having some problems doing it with mod_rewrite. I saved my scripts in the scripts directory. I put gz-compressed copies in the scripts/compressed directory.

I've found that when I request the script directly, I get the compressed file; but when the browser requests it through my page in /, I get the original uncompressed script. The addresses used in both are exactly the same.

I'd appreciate any ideas. This has me stumped.

Scripts/.htaccess

Code: Select all
RewriteEngine on
RewriteBase /scripts
RewriteCond %{HTTP_USER_AGENT} "MSIE 7|Firefox"
RewriteCond %{HTTP_ACCEPT} >gzip
RewriteRule ^(.+).js$ compressed/$1.js.gz [QSA,L]


Scripts/Compressed/.htaccess

Code: Select all
ForceType text/javascript
Header set Content-Encoding: gzip


Thanks in advance,

Wesley
init2null
 
Posts: 3
Joined: Tue Mar 03, 2009 1:42 pm

Postby richardk » Tue Mar 03, 2009 3:18 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} MSIE\s7|Firefox [NC]
RewriteCond %{HTTP_ACCEPT} gzip [NC]
RewriteRule ^(.+\.js)$ /compressed/$1.gz [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby init2null » Tue Mar 03, 2009 4:26 pm

Thanks for the reply, Richard. Unfortunately, it's still not working with your modified version when requested from HTML, and the modified version also failed when I directly requested the file.
init2null
 
Posts: 3
Joined: Tue Mar 03, 2009 1:42 pm

Postby init2null » Tue Mar 03, 2009 5:06 pm

I can't believe it. After fighting htaccess for at least five hours now, I finally found the code that will work. It looks like the gzip line was the problem. I don't know why the way it's requested makes a difference, but I'm just glad it's working.

Thanks again!

Wesley

Code: Select all
RewriteEngine on
RewriteBase /scripts
RewriteCond %{HTTP_USER_AGENT} "MSIE 7|Firefox"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule ^(.+).js$ compressed/$1.js.gz [QSA,L]
init2null
 
Posts: 3
Joined: Tue Mar 03, 2009 1:42 pm


Return to Content

Who is online

Users browsing this forum: No registered users and 13 guests

cron