- Apache HTTP 服务器 2.2.22
- Arch Linux i686
我正在使用HTML5 样板 .htaccess使用 WordPress Multisite,它需要两个 .htaccess 文件。我不确定哪个优先,所以我在每个文件中都包含了整个 H5BP 代码,直到 WP 特定的内容,如下所示:
在下面/
:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) wordpress/$1 [L]
RewriteRule ^(.*\.php)$ wordpress/$1 [L]
RewriteRule . index.php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
# END WordPress
在下面/wordpress/
:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
所有 WordPress 代码似乎都运行正常;我的网站可以正常运行。但是,样板代码却不行。例如,mod_headers 或 mod_deflate 无法生效,尽管它们已在 httpd.conf 中加载,并且我的 VirtualHost 已AllowOverride All
设置。
例如:
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=edge,chrome=1"
# `mod_headers` can't match based on the content-type, however, we only
# want to send this header for HTML pages and not for the other resources
<FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webapp|webm|webp|woff|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
…不会设置X-UA-Compatible
标头。但是,如果我直接在 PHP 中使用 执行此操作,<?php header('X-UA-Compatible: IE=edge,chrome=1'); ?>
则它确实会出现在响应中。
类似地,以下内容不会对任何内容进行 GZIP 压缩:
<IfModule mod_deflate.c>
# Force compression for mangled headers.
# http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# Compress all output labeled with one of the following MIME-types
# (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
# and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
# as `AddOutputFilterByType` is still in the core directives).
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain \
text/x-component \
text/xml
</IfModule>
</IfModule>
我该如何解决这个问题?
答案1
希望你现在已经解决了这个问题。我只是想指出这帮助我解决了我的问题。
# Compress all output labeled with one of the following MIME-types
# (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
# and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
# as `AddOutputFilterByType` is still in the core directives).
您在搜索答案时发布的上述片段给了我一些线索。mod_filter 是否已启用?我检查过,没有,这可以阻止这种情况的发生。
就像 Honoki 所说的那样,确保 (mod_rewrite、mod_headers、mod_deflate、mod_setenvif、mod_filter) 已安装和/或启用,以使 Boilerplates 的 mod_deflate 部分能够正常工作。