Skip to content

Instantly share code, notes, and snippets.

@LBeckX
Last active July 13, 2023 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LBeckX/b7a304d961c0a24f5aeeea4b11f120dd to your computer and use it in GitHub Desktop.
Save LBeckX/b7a304d961c0a24f5aeeea4b11f120dd to your computer and use it in GitHub Desktop.
Contao - Htaccess
RewriteEngine on
RewriteBase /
# HTTP-Auth
#AuthType Basic
#AuthName "Freigabeserver"
#AuthUserFile /path/to/.htpasswd
#Require valid-user
# HTTPS-Auth
#<If "%{HTTPS} == 'on'">
#AuthType Basic
#AuthName "Freigabeserver"
#AuthUserFile /path/.htpasswd
#AuthMerging And
#Require valid-user
#</If>
# Block all requests
#ErrorDocument 403 http://www.domain.tkd
#Deny from all
# Redirect to HTTPS
#RewriteCond %{HTTPS} off
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]
# Redirect all mapped domains to primary domain
#RewriteCond %{HTTP_HOST} !^DOMAIN\.TLD$ [nc]
#RewriteRule (.*) http://DOMAIN.TLD/$1 [R=permanent,nc,L]
# Redirect single domains
#RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
#RewriteRule (.*) http://example.com/$1 [R=301,L]
# Require https
#RewriteCond %{SERVER_PORT} !^443$ [nc]
#RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=permanent,nc,L]
# Rewrite favicon.ico on multisite-installations
#RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.de$ [NC]
#RewriteRule ^favicon.ico$ /files/domain1/layout/favicon.ico [L]
# Redirect / to subdir
#RewriteRule ^$ /contenido/ [R=301,L]
# SEO-Redirects (with path)
#RedirectPermanent /oldUrl /newUrl
# SEO-Redirects (without path, case-insensitive)
#RedirectMatch Permanent (?i)/oldUrl /newUrl
# Shortlink w/ monitoring
#RewriteCond %{HTTP_HOST} ^(www\.)?jobs.xxx\.de$ [NC]
#RewriteRule (.*) https://www.xxx.de/jobs [R=301,L]
#RedirectMatch Permanent ^(?i)/jobs /de/unternehmen/jobs.html
# SEO/Performance
#Header set Connection keep-alive
# Support httpAuth at fast-cgi
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
# Proxy-Rewriting
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ https://xxx.tld/$1 [L,P]
# Error Document
#ErrorDocument 404 /error-404.html
#ErrorDocument 403 /error-403.html
# Fixing old allow/deny from all in subfolders (of contao)
# == OLD ==
# order deny,allow
# #allow from all
# == NEW ==
# <IfModule !mod_authz_core.c>
# Order deny,allow
# Allow from all
# </IfModule>
# <IfModule mod_authz_core.c>
# Require all granted
# </IfModule>
# add trailing slashes if not set (only with / as url suffix)
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301]
######### Contao 4 htaccess definitions: gzip-Compression, Encoding, Cache #########
##
# Header adjustments
##
<IfModule mod_headers.c>
# 1 Month for most static assets
<filesMatch ".(jpg|jpeg|png|gif|ico|woff|woff2|svg|ttf|ttc|svgz|webp)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
<filesMatch ".(css|js)$">
Header set Cache-Control "max-age=3600, public"
</filesMatch>
##
# For more information see: https://github.com/contao/core/issues/4364
##
<FilesMatch "\.(js|css|xml|gz|svgz)$">
Header append Vary Accept-Encoding
</FilesMatch>
##
# Do not cache source map files
# @see https://github.com/contao/core/issues/8532
##
<FilesMatch "\.map$">
Header set Expires "0"
Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform"
</FilesMatch>
</IfModule>
##
# Disable ETags
# @see http://developer.yahoo.com/performance/rules.html#etags
##
FileETag None
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
##
# Set the proper MIME types
# @see https://github.com/h5bp/html5-boilerplate
##
<IfModule mod_mime.c>
AddType application/javascript js jsonp
AddType application/json json
AddType audio/ogg oga ogg
AddType audio/mp4 m4a f4a f4b
AddType video/ogg ogv
AddType video/mp4 mp4 m4v f4v f4p
AddType video/webm webm
AddType video/x-flv flv
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf ttc
AddType font/opentype otf
AddType application/x-font-woff woff woff2
AddType image/x-icon ico
AddType image/webp webp
AddType text/cache-manifest appcache manifest
AddType text/x-component htc
AddType application/xml rss atom xml rdf
AddType application/x-web-app-manifest+json webapp
AddType text/x-vcard vcf
AddType application/x-shockwave-flash swf
AddType application/font-woff woff
AddType application/font-woff2 woff2
</IfModule>
##
# Gzip compression
# @see https://github.com/h5bp/html5-boilerplate
##
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</IfModule>
</IfModule>
##
# Expires headers (for better cache control)
# @see https://github.com/h5bp/html5-boilerplate
##
<IfModule mod_expires.c>
ExpiresActive on
##
# Productional website
##
ExpiresByType text/cache-manifest "access plus 0 seconds"
ExpiresByType text/html "access plus 1 hour"
ExpiresByType text/xml "access plus 1 hour"
ExpiresByType application/xml "access plus 1 hour"
ExpiresByType application/json "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"
ExpiresByType text/x-component "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType text/css "access plus 1 hour"
ExpiresByType application/javascript "access plus 1 hour"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment