Skip to content

Instantly share code, notes, and snippets.

@ADoebeling
Last active August 8, 2017 12:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ADoebeling/2a327f9ba27863ec7eed to your computer and use it in GitHub Desktop.
Save ADoebeling/2a327f9ba27863ec7eed to your computer and use it in GitHub Desktop.
.htaccess-defaults
# .htaccess-defaults
# Some often used .htaccess-parameters
#
# @Author: Andreas Doebeling <ad@1601.com>
# @Copyright: 1601.communication gmbh
# @Link: http://www.1601.com
# @Link: http://xing.doebeling.de
# Always required at 1601-Hosting
RewriteEngine on
RewriteBase /
# HTTP-Auth
#AuthType Basic
#AuthName "Freigabeserver - contact admin@1601.com"
#AuthUserFile /path/to/.htpasswd
#Require valid-user
# Block all requests
#ErrorDocument 403 http://www.domain.tkd
#Deny from all
# 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]
#RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.de$ [NC]
#RewriteRule ^favicon.ico$ /files/domain2/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>
@LBeckX
Copy link

LBeckX commented Jan 27, 2017

# Redirect single domains
#RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
#RewriteRule (.*) http://example.com/$1 [R=301,L]

hier sollte m. E. ^www\.example\.com$ zu ^(www\.)?example\.com$ geändert werden

@ADoebeling
Copy link
Author

@LBeckX Danke, done!

@Xendiadyon
Copy link

Xendiadyon commented Jan 31, 2017

hier fehlt noch das Hinzufügen von Slashes falls sie weggelassen sind und man URLs ohne .html und stattdessen mit / generieren lässt.

# 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]

@LBeckX
Copy link

LBeckX commented Feb 24, 2017

.html auf /
RewriteRule ^(.*)\.html$ $1/ [R=301,L]

  • Contao.htaccess URL-Suffix = /
RewriteCond %{REQUEST_FILENAME} !\.(htm|php|js|css|map|htc|png|gif|jpe?g|ico|xml|csv|txt|swf|flv|mp4|webm|ogv|mp3|ogg|oga|eot|otf|tt[cf]|woff2?|svgz?|pdf|zip|gz)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

@LBeckX
Copy link

LBeckX commented Mar 20, 2017

Wir haben die Möglichkeit, HTTP-Requests von der Passwortabfrage auszunehmen.
Somit wird ZUERST eine Weiterleitung auf https erzwungen, UND DANN ERST findet eine Passwortabfrage statt (bei der das Passwort dann praktischerweise auch direkt verschlüsselt übertragen wird).
In meinen Augen deutlich sinnvoller und angenehmer: Nur eine Passwortabfrage und nicht 2-5 ;)

Einen Nachteil hat es aber:
Wenn der HTTPS-Zwang nicht funktioniert oder nicht eingeschaltet ist, ist die Seite logischerweise uneingeschränkt per HTTP erreichbar.
Man muss also sein Hirn einschalten und den (sowieso obligatorischen) HTTPS-Zwang auf jeden Fall mit einbinden.

<If "%{HTTPS} == 'on'">
AuthType Basic
AuthName "Freigabeserver - contact admin@1601.com"
AuthUserFile /kunden/226796_91058/kunden/lbv.de/www/.htpasswd
AuthMerging And
Require valid-user
</If>

Quelle: https://github.com/ADoebeling/Digital-Meeting/issues/5

@Xendiadyon
Copy link

außerdem fehlt noch die bessere Möglichkeit, um SSL zu aktivieren:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]

@ao1601com
Copy link

Weiterleitung domainspezifischer Sitemap

RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.de$ [NC]
RewriteRule ^sitemap.xml$  share/sitemap1.xml [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.de$ [NC]
RewriteRule ^sitemap.xml$  share/sitemap2.xml [R=301,L]

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