這是我的 htaccess 模板,我想知道是否可以添加任何內容來提高網站效能。
# Defaults
AddDefaultCharset UTF-8
DefaultLanguage en-US
ServerSignature Off
FileETag None
Header unset ETag
Options -MultiViews
#Options All -Indexes
# Force the latest IE version or ChromeFrame
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
</IfModule>
</IfModule>
# Proxy X-UA Setup
<IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
#Rewrites
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# Redirect to non-WWW
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Redirect to WWW
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
# Redirect index to root
RewriteRule ^(.*)index\.(php|html)$ /$1 [R=301,L]
# Caching
ExpiresActive On
ExpiresDefault A0
Header set Cache-Control "public"
# 1 Year Long Cache
<FilesMatch "\.(flv|fla|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|png|jpg|jpeg|gif|swf|js|css|ttf|eot|woff|svg|svgz)$">
ExpiresDefault A31622400
</FilesMatch>
# Proxy Caching
<FilesMatch "\.(css|js|png)$">
ExpiresDefault A31622400
Header set Cache-Control "private"
</FilesMatch>
# Protect against DOS attacks by limiting file upload size
LimitRequestBody 10240000
# Proper SVG serving
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
# GZip Compression
<IfModule mod_deflate.c>
<FilesMatch "\.(php|html|css|js|xml|txt|ttf|otf|eot|svg)$" >
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
# Error page
ErrorDocument 404 /404.html
# Deny access to sensitive files
<FilesMatch "\.(htaccess|ini|log|psd)$">
Order Allow,Deny
Deny from all
</FilesMatch>
答案1
簡單:將 htaccess 內容移至伺服器設定。
每次完成對包含資料夾的請求時,都會讀取並解析 htaccess 檔案。另一方面,伺服器配置只能讀取一次。
如果您無法在 httpd.conf 中移動這些行,請嘗試將它們放在「Directory」標記中,特別是當其中一些行連結到特定目錄時。