Created
November 20, 2017 15:37
-
-
Save anwerashif/334e1e583b2419222e7a900e4fbb9a66 to your computer and use it in GitHub Desktop.
WordPress Speed Optimization via .htaccess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Disable ETags | |
<IfModule mod_headers.c> | |
Header unset ETag | |
Header set Connection keep-alive | |
</IfModule> | |
FileETag None | |
############## MaxCDN Fix ############# | |
<IfModule mod_headers.c> | |
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$"> | |
Header set Access-Control-Allow-Origin "*" | |
</FilesMatch> | |
</IfModule> | |
########### REDIRECT TRAFFIC TO HTTPS ############ | |
# RewriteEngine On | |
# RewriteCond %{HTTPS} off | |
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] | |
############ SECURITY ########### | |
<FilesMatch "\.(md|exe|sh|bak|inc|pot|po|mo|log|sql)$"> | |
Order allow,deny | |
Deny from all | |
</FilesMatch> | |
<Files robots.txt> | |
Allow from all | |
</Files> | |
############## CACHING-GZIP ############ | |
<IfModule mod_expires.c> | |
ExpiresActive On | |
ExpiresDefault A2592000 | |
<FilesMatch "\.(txt|xml|js)$"> | |
ExpiresDefault A2592000 | |
</FilesMatch> | |
<FilesMatch "\.(css)$"> | |
ExpiresDefault A2592000 | |
</FilesMatch> | |
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$"> | |
ExpiresDefault A2592000 | |
</FilesMatch> | |
<FilesMatch "\.(jpg|jpeg|png|gif|swf|webp)$"> | |
ExpiresDefault A2592000 | |
</FilesMatch> | |
</IfModule> | |
<IfModule mod_headers.c> | |
<FilesMatch "\.(txt|xml|js)$"> | |
Header set Cache-Control "max-age=2592000" | |
</FilesMatch> | |
<FilesMatch "\.(css)$"> | |
Header set Cache-Control "max-age=2592000" | |
</FilesMatch> | |
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac)$"> | |
Header set Cache-Control "max-age=2592000" | |
</FilesMatch> | |
<FilesMatch "\.(jpg|jpeg|png|gif|swf|webp)$"> | |
Header set Cache-Control "max-age=2592000" | |
</FilesMatch> | |
</IfModule> | |
<IfModule mod_deflate.c> | |
<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> | |
<IfModule mod_filter.c> | |
AddOutputFilterByType DEFLATE "application/atom+xml" \ | |
"application/javascript" \ | |
"application/json" \ | |
"application/ld+json" \ | |
"application/manifest+json" \ | |
"application/rdf+xml" \ | |
"application/rss+xml" \ | |
"application/schema+json" \ | |
"application/vnd.geo+json" \ | |
"application/vnd.ms-fontobject" \ | |
"application/x-font-ttf" \ | |
"application/x-javascript" \ | |
"application/x-web-app-manifest+json" \ | |
"application/xhtml+xml" \ | |
"application/xml" \ | |
"font/eot" \ | |
"font/opentype" \ | |
"image/bmp" \ | |
"image/svg+xml" \ | |
"image/vnd.microsoft.icon" \ | |
"image/x-icon" \ | |
"text/cache-manifest" \ | |
"text/css" \ | |
"text/html" \ | |
"text/javascript" \ | |
"text/plain" \ | |
"text/vcard" \ | |
"text/vnd.rim.location.xloc" \ | |
"text/vtt" \ | |
"text/x-component" \ | |
"text/x-cross-domain-policy" \ | |
"text/xml" | |
</IfModule> | |
<IfModule mod_mime.c> | |
AddEncoding gzip svgz | |
</IfModule> | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment