htaccess rewrite auf https ohne www.
Hallo,
was ist die "best practice" für die Weiterleitung aller Anfragen auf https: ohne .www?
Alle Vorschläge, die ich bisher gegoogelt habe, legen entweder die Site komplett lahm, z.B. wegen zu vielen Redirects, oder lösen das Problem nicht vollständig. Mit den aktuell eingestellten Regeln, siehe unten, schaffe ich folgendes:
1) http://domain.tld -> http://domain.tld/Seitenalias
2) http://www.domain.tld -> https://domain.tld/Seitenalias
3) https://domain.tld -> https://domain.tld/Seitenalias
4) https://www.domain.tld -> https://domain.tld/Seitenalias
2) bis 4) ist für mich perfekt. 1) auch noch hinzubiegen, scheint mir inzwischen eine übermenschliche Aufgabe.
Hier ist mein aktueller Rewrite Abschnitt aus .htaccess:
##
# URL rewriting
##
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
##
# If you cannot use mod_deflate, uncomment the following lines to load a
# compressed .gz version of the aggregated Contao JavaScript and CSS files.
##
#AddEncoding gzip .gz
#<FilesMatch "\.js\.gz$">
# AddType "application/javascript" .gz
#</FilesMatch>
#<FilesMatch "\.css\.gz$">
# AddType "text/css" .gz
#</FilesMatch>
#RewriteCond %{HTTP:Accept-encoding} gzip
#RewriteCond %{REQUEST_FILENAME} \.(js|css)$
#RewriteCond %{REQUEST_FILENAME}.gz -f
#RewriteRule ^(.*)$ $1.gz [QSA,L]
##
# By default, Contao adds ".html" to the generated URLs to simulate static
# HTML documents. If you change the URL suffix in the back end settings, make
# sure to change it here accordingly!
#
# RewriteRule .*\.html$ index.php [L] # URL suffix .html
# RewriteRule .*\.txt$ index.php [L] # URL suffix .txt
# RewriteRule .*\.json$ index.php [L] # URL suffix .json
#
# If you do not want to use an URL suffix at all, you have to add a third
# line to prevent URLs that point to folders from being rewritten (see #4031).
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
# If you are using mod_cache, it is recommended to use the RewriteRule below,
# which adds the query string to the internal URL:
#
# RewriteRule (.*\.html)$ index.php/$1 [L]
#
# Note that not all environments support mod_rewrite and mod_cache.
##
RewriteCond %{REQUEST_FILENAME} !\.(htm|php|js|css|map|htc|png|gif|jpe?g|ico|xml|c sv|txt|swf|flv|mp4|webm|ogv|mp3|ogg|oga|eot|otf|tt[cf]|woff2?|svgz?|pdf|zip|gz)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*\.html$ index.php [L]
##
# The following rules are required if you want to pass the language as first
# URL parameter (added in Contao 2.11). The first rule rewrites the empty URL
# to the front end controller, the second one adds a missing trailing slash.
##
# RewriteRule ^[a-z]{2}(\-[A-Z]{2})?/$ index.php [L]
# RewriteRule ^([a-z]{2}(\-[A-Z]{2})?)$ $1/ [R=301,L]
</IfModule>
Besten Dank im Voraus
Wolfram