Úprava .htaccess pro adresu s www i bez www

Verze pro tiskVerze pro tisk
Modul: 

https://www.cms-systemy.cz/forum/rady-tipy-triky-host/69-htaccess-www-a-...

# dalsi info a priklady: http://kb.wedos.com/r/32/webhosting-htaccess.html

 

příklad funkčního souboru:

 

RewriteEngine On

# presmerovani na variantu s www cele domeny (aliasy)
RewriteCond %{HTTP_HOST} ^([^\.]*)\.([^\.]*)$
RewriteRule (.*) https://www.%1.%2/$1 [L,R=301]

# presmerovani na variantu bez www subdomeny
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.([^.]+)\.([^\.]*)$ [NC]
RewriteRule ^(.*)$ https://%1.%2.%3/$1 [L,R=301]

# cele domeny (aliasy)
RewriteCond %{REQUEST_URI} !^domains/
RewriteCond %{REQUEST_URI} !^/domains/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteCond %{DOCUMENT_ROOT}/domains/%2 -d
RewriteRule (.*) domains/%2/$1 [DPI]

# subdomeny (s nebo bez www na zacatku)
RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]

# aliasy - spravne presmerovani pri chybejicim /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]

# subdomeny - spravne presmerovani pri chybejicim /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]

RewriteEngine On
# all redirection HTTP -> HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]