Skip to content

Instantly share code, notes, and snippets.

@perezdans
Last active November 9, 2021 13:06
Show Gist options
  • Save perezdans/e04b929f989744df6a6884078145619d to your computer and use it in GitHub Desktop.
Save perezdans/e04b929f989744df6a6884078145619d to your computer and use it in GitHub Desktop.
.htaccess para WordPress para cumplir requisitos de pagespeed insights tanto de Caché de archivos como de compresión de ficheros
# 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
# -----------------------------------------------------------------------
# EXPIRES CACHING: una semana
# -----------------------------------------------------------------------
<IfModule mod_expires.c>
ExpiresActive on
#Varios
ExpiresByType application/pdf A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType image/vnd.microsoft.icon A2592000
ExpiresByType image/svg+xml A2592000
#Imagenes
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/webp A2592000
#Media
ExpiresByType video/ogg A2592000
ExpiresByType audio/ogg A2592000
ExpiresByType video/mp4 A2592000
ExpiresByType video/webm A2592000
#CSS/JS
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType application/x-javascript A2592000
#Fuentes
ExpiresByType application/x-font-ttf A2592000
ExpiresByType application/x-font-woff A2592000
ExpiresByType application/font-woff A2592000
ExpiresByType application/font-woff2 A2592000
ExpiresByType application/vnd.ms-fontobject A2592000
ExpiresByType font/ttf A2592000
ExpiresByType font/woff A2592000
ExpiresByType font/woff2 A2592000
</IfModule>
<FilesMatch "\.(ico|gif|jpg|png|flv|pdf|mp3|js|css|xml)$">
Header set Cache-Control "max-age=2592000"
Header always unset Set-Cookie
Header unset ETag
FileETag None
</FilesMatch>
# -----------------------------------------------------------------------
# Definimos MIME types para asegurarnos de que el servidor los conoce.
# -----------------------------------------------------------------------
<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>
# -----------------------------------------------------------------------
# Comprimimos ficheros
# -----------------------------------------------------------------------
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.gzip.
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment