0

I have a SPA that resides in a subfolder on a website that this .htaccess redirect works fine for

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . ./ [L]

Basically if the file or directory doesn't already exist point it back to the route of the directory.

However, I wanted to add this to the rewrite rules

RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [R=307,L]

Which would check to see if there is a .gz version of a file and serve that instead.

I've tried everything I can think of, but haven't found a way to get this to work as expected.

qw3n
  • 6,236
  • 6
  • 33
  • 62

1 Answers1

0

Replacing the code section at the bottom with https://stackoverflow.com/a/9158330/379650 answer fixed the problem.

# AddEncoding allows you to have certain browsers uncompress information on the fly.
AddEncoding gzip .gz

#Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
Community
  • 1
  • 1
qw3n
  • 6,236
  • 6
  • 33
  • 62