# Vorschlag und Anregung fr Nutzer der Webseiten-Vorlage: Datei .htaccess.txt:
#-------------------------------------------------------------------------------
# Schalten Sie in Ihrem Editor die Syntax-Hervorhebung fr "Apache config" ein.
# Beachten Sie: Diese Regeln sind Vorschlge und nicht vollstndig.
#               Sie selbst sind veranwortlich. Keine Haftung durch mich.
#               Beachten Sie die Hinweise auf dieser Seite:
#               https://webseiten-vorlage.seopunkt.de/htaccess-regeln.php
# erstellt von Gsta Thomas, Fassung vom 15.10.2022  
#-------------------------------------------------------------------------------

#--- Verzeichnis-Browsing verhindern: ------------
Options -Indexes
DirectoryIndex index.php

#--- Zeichensatz im header ausgeben? nein, denn --
#--- UTF-8 ist bei PHP-Seiten Std.-Kodierung -----
# AddDefaultCharset UTF-8

#--- Mime type fr webmanifest zuweisen: --------- 
AddType application/manifest+json webmanifest

<IfModule mod_rewrite.c>

#--- mod_rewrite initialisieren: -----------------
  RewriteEngine on
  RewriteBase /

#--- eindeutige Erreichbarkeit (kanonische URL) --
#    sicherstellen nach Muster Jrg Kruse: -------
#--- 1: WL von mit-www nach ohne-www (Server), ---
#--- 2: WL von http nach https mit s (Server): ---
  RewriteCond %{HTTP_HOST} !^example\.com$ [OR]
  RewriteCond %{SERVER_PORT} !^443$
  RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
#--- 3: WL von /index.php  nach / (Server): ------
  RewriteCond %{QUERY_STRING} ^$
  RewriteCond %{THE_REQUEST} /index\.php
  RewriteRule ^index\.php https://example.com/ [R=301,L]

</IfModule>

#--- Fehlerseite anz., wenn Seite nicht vorhand. - 
#--- wenn (s. phpinfo) Server API FPM/FastCGI: --- 
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*) fehler-404.php
#--- wenn (s. phpinfo) Server API CGI/FastCGI ----
#    oder wenn Server API Apache 2.0 Handler: ----
# ErrorDocument 404 /fehler-404.php

#--- Spambots aussperren: ------------------------
order deny,allow
deny from 85.25.71.197
deny from 85.25.207.105
deny from 188.138.41.173
deny from 138.201.30.66
deny from 136.243.48.85
deny from 136.243.103.153
deny from 207.241.231.149
deny from 84.200.55.90
deny from 124.104.255.153
# ggf. weitere ergnzen

#--- Scraper-Abwehr: -----------------------------
<IfModule mod_rewrite.c>
  RewriteCond %{HTTP_REFERER} ^http://buttons-for-website\.com [NC,OR]
  RewriteCond %{HTTP_REFERER} ^http://.*7makemoneyonline\.com/ [NC,OR]
  RewriteCond %{HTTP_REFERER} ^http://videos-for-your-business\.com [NC,OR]
  RewriteCond %{HTTP_REFERER} ^http://success-seo\.com [NC,OR]
  RewriteCond %{HTTP_REFERER} ^http://rankings-analytics\.com [NC,OR]
  RewriteCond %{HTTP_REFERER} ^http://free-video-tool\.com [NC,OR]
  RewriteCond %{HTTP_REFERER} ^http://1-99seo\.com [NC,OR]
  RewriteCond %{HTTP_REFERER} ^http://1-free-share-buttons\.com [NC,OR]
  RewriteCond %{HTTP_REFERER} ^http://3-letter-domains\.net [NC,OR]
  RewriteCond %{HTTP_REFERER} ^http://.*semalt\.com/ [NC]
  # ggf. weitere ergnzen (der letzte *ohne* OR)
  RewriteRule ^(.*)$ - [F,L]
</IfModule>

#--- Cache-Verhalten festlegen je Typ: -----------
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 2 days"
	ExpiresByType text/html "access plus 6 hours"
  ExpiresByType text/css "modification plus 10 years"
  ExpiresByType text/x-component "access plus 1 year"
  ExpiresByType text/javascript "access plus 8 days"
  ExpiresByType application/javascript "access plus 8 days"
  ExpiresByType application/json "access plus 1 year"
  ExpiresByType application/xml "access plus 6 hours"
  ExpiresByType application/manifest+json "access plus 1 year"
  ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  # ggf. weitere ergnzen
</IfModule>

<IfModule mod_headers.c>

#--- robots.txt + PDF-Dat auf noindex setzen: ----
  <FilesMatch "robots\.txt$">
    Header append X-Robots-Tag "noindex"
  </FilesMatch>
  <FilesMatch "\.pdf$">
    Header set X-Robots-Tag "noindex, follow"
  </FilesMatch>

#--- Sicherheitseinstellungen festlegen: ---------
  Header set X-Frame-Options SAMEORIGIN
  Header set X-XSS-Protection "1; mode=block"
  Header set X-Content-Type-Options: nosniff
  Header set Referrer-Policy: same-origin

#--- Verschiedene HTTP-Kopfzeilen: ---------------
  Header unset ETag
  Header unset Pragma
  Header unset X-Powered-By
  Header unset Server
  Header set Cache-Control "private, must-revalidate"
  # Header set MyHeader "Element bereitgestellt in %D mikrosec"

</IfModule>

#--- Vorab-Komprimierung GZIP fr css|js: --------
#--- bei einigen Webhostern nicht erforderlich! --
<IfModule mod_headers.c>
  <FilesMatch "\.css\.gz$">
    ForceType text/css
    Header set Content-Encoding: gzip
    Header append Vary Accept-Encoding
  </FilesMatch>
  <FilesMatch "\.js\.gz$">
    ForceType text/javascript
    Header set Content-Encoding: gzip
    Header append Vary Accept-Encoding
  </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>

#--- noch: Vorab-Komprimierung GZIP fr css|js: --
  RewriteCond %{HTTP:Accept-Encoding} gzip
  RewriteCond %{REQUEST_URI} \.(css|js)$
  RewriteCond %{REQUEST_FILENAME}.gz -f
  RewriteRule ^(.*)$ /$1.gz [L]

#--- Weiterleit von ThickBox-Adresse zu /... : ---
  RewriteCond %{QUERY_STRING} keepThis
  RewriteRule ^(.*)$ https://example.com/$1? [L,R=301]

#--- Weiterleit von iframe-Param-Adr zu /... : ---
  RewriteCond %{QUERY_STRING} iframe
  RewriteRule ^(.*)$ https://example.com/$1? [L,R=301]

#--- Bilderklau verhind., Ersatzbild anzeigen: ---
  # RewriteCond %{HTTP_REFERER} chopper\.de [NC,OR]
  # RewriteCond %{HTTP_REFERER} vebidoo\.de [NC,OR]
  # RewriteCond %{HTTP_REFERER} photoppi\.com
  # ggf. weitere ergnzen (der letzte *ohne* NC,OR)
  # RewriteCond %{REQUEST_URI} bilder
  # RewriteRule ^ https://example.com/z-sonst/stopp-bilder-hotlinking.jpg [T=image/jpeg,L]

</IfModule>

#--- gezielte Weiterleit. einzelner Adressen: ----
Redirect permanent /alter-name.php https://example.com/neuer-name.php
# bitte beachten: "never change a running url!" --

# Ende der Datei ---