首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.htaccess规则适用于某些页面,但不适用于其他页面。

.htaccess规则适用于某些页面,但不适用于其他页面。
EN

Stack Overflow用户
提问于 2014-09-14 06:06:56
回答 1查看 356关注 0票数 1

我正试图使用谷歌PageSpeed洞察来加速我的网站-- www.edmhunters.com。

首先,下面是我的.htaccess文件的样子

代码语言:javascript
复制
# -----------------------------------------------------------------------
# Caching for 1 Year
# -----------------------------------------------------------------------
<FilesMatch "\.(ico|svg|woff|eot|ttf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

# -----------------------------------------------------------------------
# Caching for 1 Week
# -----------------------------------------------------------------------
<FilesMatch "\.(jpg|png|gif|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# -----------------------------------------------------------------------
# Defining MIME types to ensure the web server actually knows about them
# -----------------------------------------------------------------------
<IfModule mod_mime.c>
    AddType application/javascript          js
    AddType application/vnd.ms-fontobject   eot
    AddType application/x-font-ttf          ttf ttc
    AddType font/opentype                   otf
    AddType application/x-font-woff         woff
    AddType image/svg+xml                   svg svgz 
    AddEncoding gzip                        svgz
</Ifmodule>

# -----------------------------------------------------------------------
# Compressing output
# -----------------------------------------------------------------------
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
    AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
    AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</Ifmodule>

奇怪的是,Cache-Control头只用于媒体文件,而不是静态文件。

例如:2.jpg在redbot.org上的输出如下

代码语言:javascript
复制
 HTTP/1.1 200 OK
    Date: Sun, 14 Sep 2014 06:01:54 GMT
    Server: Apache/2.4.7 (Ubuntu)
    Last-Modified: Thu, 11 Sep 2014 13:52:29 GMT
    ETag: "7391-502ca7aba5a6e"
    Accept-Ranges: bytes
    Content-Length: 29585
    Cache-Control: max-age=604800, public
    Keep-Alive: timeout=5, max=100
    Connection: Keep-Alive
    Content-Type: image/jpeg

http://www.edmhunters.com/static/img/bp-logo.9bf55788f1b6.jpg的输出如下所示

代码语言:javascript
复制
HTTP/1.1 200 OK
    Date: Sun, 14 Sep 2014 05:43:28 GMT
    Server: Apache/2.4.7 (Ubuntu)
    Last-Modified: Tue, 26 Aug 2014 05:43:32 GMT
    ETag: 1409031812.62
    Content-Length: 2592
    Keep-Alive: timeout=5, max=100
    Connection: Keep-Alive
    Content-Type: image/jpeg

另外,根据谷歌PageSpeed窥探我的主页,HTML被缩小了,而谷歌PageSpeed窥探另一个页面说我的HTML没有缩小。

为什么会有这种不同的行为?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-14 18:40:17

我使用Django服务我的静态文件,而我的媒体文件使用Apache。通过Apache服务我的静态文件解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25830559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档