Skip to content

Instantly share code, notes, and snippets.

@VovanZver
Created June 23, 2016 15:37
Show Gist options
  • Save VovanZver/f53dd46aa8553f89d8a8a2e1aa5dc6ae to your computer and use it in GitHub Desktop.
Save VovanZver/f53dd46aa8553f89d8a8a2e1aa5dc6ae to your computer and use it in GitHub Desktop.
htaccess with cache headers
<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>
SetEnvIf Host ^nocache\.vmagroup\.com$ NOCACHE
<IfModule mod_headers.c>
# Cache images for a long time
<FilesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header always set Cache-Control "public, s-maxage=31556900, max-age=31556900" env=!NOCACHE
</FilesMatch>
<FilesMatch "\.(eot|otf|tt[cf]|woff2?)$">
Header always set Access-Control-Allow-Origin "*"
</FilesMatch>
# Cache js/css for 30 mins
<FilesMatch "\.(css|js|eot|svg|ttf|woff|otf)$">
Header always set Cache-Control "public, s-maxage=1800, max-age=1800" env=!NOCACHE
</FilesMatch>
# Cache php results for 15 mins - do not use for symfony
<FilesMatch "\.php$">
Header always set Cache-Control "public, s-maxage=900, max-age=900" env=!NOCACHE
</FilesMatch>
<FilesMatch "^(wp-admin)">
Header always set Cache-Control "no-cache"
</FilesMatch>
# Somethings like Joomla set this things
Header always unset Pragma
Header always unset Expires
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^vmagroup\.com [NC]
RewriteRule ^(.*)$ http://www.vmagroup.com/$1 [L,R=301,NC]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# protect xmlrpc
<Files xmlrpc.php>
Order Deny,Allow
Deny from all
</Files>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment