Skip to content

Instantly share code, notes, and snippets.

@maxfenton
Last active March 18, 2019 19:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxfenton/51d6b59329e1841a9e7e to your computer and use it in GitHub Desktop.
Save maxfenton/51d6b59329e1841a9e7e to your computer and use it in GitHub Desktop.
5880.me htaccess
#######################
### //5880.me/.htaccess
#######################
AddType text/plain .map
#############
# BEGIN iThemes Security
# BEGIN Ban Users
# Begin HackRepair.com Blacklist
# RewriteEngine on
# ... lots of things
# RewriteRule ^.* - [F,L]
#############
<files .htaccess>
Order allow,deny
Deny from all
</files>
#############
# Disable directory browsing
Options -Indexes
#############
<FilesMatch "\.(css|htc|less|js|js2|js3|js4|CSS|HTC|LESS|JS|JS2|JS3|JS4)$">
<IfModule mod_headers.c>
Header unset Set-Cookie
</IfModule>
</FilesMatch>
<FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip|ASF|ASX|WAX|WMV|WMX|AVI|BMP|CLASS|DIVX|DOC|DOCX|EOT|EXE|GIF|GZ|GZIP|ICO|JPG|JPEG|JPE|JSON|MDB|MID|MIDI|MOV|QT|MP3|M4A|MP4|M4V|MPEG|MPG|MPE|MPP|OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|PNG|POT|PPS|PPT|PPTX|RA|RAM|SVG|SVGZ|SWF|TAR|TIF|TIFF|TTF|TTC|WAV|WMA|WRI|WOFF|XLA|XLS|XLSX|XLT|XLW|ZIP)$">
<IfModule mod_headers.c>
Header unset Set-Cookie
</IfModule>
</FilesMatch>
################# REDIRECT LINKS (and Kirby)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
#############
### Redirects
RewriteRule ^2015/?$ /in/2015/ [R=301,NC,L]
RewriteRule ^2014/?$ /in/2014/ [R=301,NC,L]
RewriteRule ^2013/?$ /in/2013/ [R=301,NC,L]
RewriteRule ^2012/?$ /in/2012/ [R=301,NC,L]
RewriteRule ^2011/?$ /in/2011/ [R=301,NC,L]
############
### Security
## block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L]
## block all files in the site folder from being accessed directly
RewriteRule ^site/(.*) error [R=301,L]
## block all files in the kirby folder from being accessed directly
RewriteRule ^kirby/(.*) error [R=301,L]
## Rules to block unneeded HTTP methods
RewriteCond %{REQUEST_METHOD} ^(TRACE|DELETE|TRACK) [NC]
RewriteRule ^(.*)$ - [F]
#############
#############
### Real Files
## if this is an existing folder/file then leave
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]
#############
#############
## Not real files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#############
### Cache-busting of JS and CSS versions
RewriteRule ^(.*)\.([0-9\-\.]+)\.(js|css)$ $1.$3 [L]
#############
### Trailing Slashes
## Add trailing slashes if none
# RewriteRule ^/?(.+)([^/])$ $1$2/ [R=301,L]
#############
### Don't break old links — /yyymmdd/stub
RewriteRule ^([0-9]{4})([0-9]{4})/(.*)?$ /in/$1/$3 [R=301,NC,L]
#############
### The Panel
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]
####################
### Kirby Site Pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/? index.php [L]
</IfModule>
################# PERFORMANCE
#############
# GZIP
<IfModule deflate_module>
<IfModule filter_module>
AddOutputFilterByType DEFLATE text/plain text/html text/text
AddOutputFilterByType DEFLATE text/xml application/xml application/xhtml+xml application/xml-dtd
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml image/svg+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE font/otf font/opentype application/font-otf application/x-font-otf
AddOutputFilterByType DEFLATE font/ttf font/truetype application/font-ttf application/x-font-ttf
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
</IfModule>
</IfModule>
#############
# EXPIRES CACHING
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType application/vnd.ms-fontobject "access plus 2 month"
ExpiresByType application/x-font-ttf "access plus 2 months"
ExpiresByType application/x-font-woff "access plus 2 months"
ExpiresByType font/opentype "access plus 2 months"
ExpiresByType text/javascript "access plus 1 day"
ExpiresByType application/javascript "access plus 1 day"
ExpiresByType application/x-javascript "access plus 1 day"
ExpiresByType image/svg+xml "access plus 1 week"
ExpiresByType text/css "access plus 1 hour"
ExpiresByType text/plain "access plus 1 hour"
ExpiresByType text/html "access plus 1 hour"
ExpiresByType text/text "access plus 1 hour"
ExpiresDefault "access 1 day"
</IfModule>
Header set Cache-Control "max-age=290304000, public"
################# WEBFONTS
<FilesMatch ".(eot|ttf|otf|woff)">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
################# COMPATIBILITY
AddDefaultCharset UTF-8
################# php.ini
php_flag short_open_tag on
php_value upload_max_filesize 2M
################# DEVELOPMENT ONLY
# AuthUserFile .htpasswd
# AuthType Basic
# AuthName ""
# Require valid-user
# php_flag display_errors on
@watershed
Copy link

Thanks for this Max. Your feedback on @adactio's htaccess cachebusting trick helped me. I've managed to preserve Jeremy’s concision with the following tweaks:

RewriteRule ^(.+)\.(\d+)\.(js|css)$ $1.$3 [L]

@maxfenton
Copy link
Author

*I need to update this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment