.htaccess 重写SPA的URL并提供gzip文件

.htaccess 重写SPA的URL并提供gzip文件,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我有一个SPA,它位于一个网站的子文件夹中,这个.htaccess重定向可以很好地工作 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . ./ [L] 基本上,如果文件或目录不存在,请将其指向目录的路由 但是,我想将此添加到重写规则中 RewriteCond %{HTTP:Accept-Encoding} gzip RewriteCond %{REQUEST_FILENAM

我有一个SPA,它位于一个网站的子文件夹中,这个.htaccess重定向可以很好地工作

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . ./ [L]
基本上,如果文件或目录不存在,请将其指向目录的路由

但是,我想将此添加到重写规则中

RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [R=307,L]
这将检查文件是否有.gz版本,并提供相应的服务


我已经尝试了我所能想到的一切,但还没有找到一种方法让它按预期工作。

用答案替换底部的代码部分修复了问题

# 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]