Lego2012
9/26/2016 - 11:37 PM

htaccess - Template-Beispiel

htaccess - Template-Beispiel

# Redirect all users to access the site WITHOUT the www. prefix
RewriteEngine on
rewritecond %{http_host} ^www.domain.de [nc]
rewriterule ^(.*)$ http://domain.de/$1 [r=301,nc]

# Disable directory listing from this point
Options -Indexes -Multiviews

# properly handle requests coming from behind proxies
<IfModule mod_headers.c>
  Header append Vary User-Agent
</IfModule>

# Properly handle old browsers that do not support compression
<IfModule mod_deflate.c>
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  # Explicitly exclude binary files from compression just in case
  SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|pdf|swf|ico|zip|ttf|eot|svg)$ no-gzip
</IfModule>
<ifmodule mod_deflate.c="">
  <filesmatch ".(js|css)$"="">
  SetOutputFilter DEFLATE
  </filesmatch>
</ifmodule>

# Don't cache HTML or PHP
<filesMatch ".(html|php)$">
  FileETag None
  <ifModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, private, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Sat, 16 Dec 1989 05:00:00 GMT"
  </ifModule>
</filesMatch>

# Prevent viewing of htaccess file
<Files ~ "^\.ht">
  order allow,deny
  deny from all
  satisfy all
</Files>

#stop hotlinking
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?domain.de/.*$ [NC] RewriteRule .(gif|jpg|swf|flv|png)$ http://dorfladen-in-grohnde.de/hotlinking.gif [R=302,L]

# Error Pages
ErrorDocument 404 /404-error.html

# Cache Certain file types, saving bandwidth and decreasing load times
# 1 YEAR
<filesMatch ".(ico|rar|zip|jpg|jpeg|png|gif)$">
  Header set Cache-Control "max-age=29030400, public"
</filesMatch>

# 1 WEEK
<filesMatch ".(js|css|pdf)$">
Header set Cache-Control "max-age=29030400, public"
</filesMatch>

# Force all PDF files to download
# Requires Apache Header Module - this will work for any file extensions
<FilesMatch "\.(?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

# Deflate Compression by FileType
<IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/plain
 AddOutputFilterByType DEFLATE text/html
 AddOutputFilterByType DEFLATE text/xml
 AddOutputFilterByType DEFLATE text/css
 AddOutputFilterByType DEFLATE text/javascript
 AddOutputFilterByType DEFLATE application/xml
 AddOutputFilterByType DEFLATE application/xhtml+xml
 AddOutputFilterByType DEFLATE application/rss+xml
 AddOutputFilterByType DEFLATE application/atom_xml
 AddOutputFilterByType DEFLATE application/javascript
 AddOutputFilterByType DEFLATE application/x-javascript
 AddOutputFilterByType DEFLATE application/x-shockwave-flash
</IfModule>

# turns cache on for 1 month
<IfModule mod_expires.c>
 ExpiresActive On
 ExpiresByType text/css "access plus 1 month"
 ExpiresByType text/javascript "access plus 1 month"
 ExpiresByType text/html "access plus 1 month"
 ExpiresByType application/javascript "access plus 1 month"
 ExpiresByType image/gif "access plus 1 month"
 ExpiresByType image/jpeg "access plus 1 month"
 ExpiresByType image/png "access plus 1 month"
 ExpiresByType image/x-icon "access plus 1 month"
</IfModule>
<ifmodule mod_headers.c>
 <filesmatch "\\.(ico|jpe?g|png|gif|swf)$">
  Header set Cache-Control "max-age=2592000, public"
 </filesmatch>
 <filesmatch "\\.(css)$">
  Header set Cache-Control "max-age=604800, public"
 </filesmatch>
 <filesmatch "\\.(js)$">
  Header set Cache-Control "max-age=216000, private"
 </filesmatch>
</ifmodule>

# Deflate Compression by MimeType
<IfModule mod_deflate.c>
 <FilesMatch "\.(js|jpg|jpeg|gif|png|css)$">
  ExpiresActive on
  ExpiresDefault "access plus 1 month"
  SetOutputFilter DEFLATE
 </FilesMatch>
</IfModule>