Skip to content

Instantly share code, notes, and snippets.

@janpecha
Last active October 9, 2015 14:37
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 janpecha/3523358 to your computer and use it in GitHub Desktop.
Save janpecha/3523358 to your computer and use it in GitHub Desktop.
Dynamické subdomény pomocí .htaccess
### Source code moved to https://github.com/janpecha/htaccess-subdomains/ ###
## Custom Error Pages
#ErrorDocument 404 /errors/e404.html
<IfModule mod_dir.c>
DirectorySlash Off
</IfModule>
Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
## Custom Error Pages
#RewriteCond %{REQUEST_URI} ^/my-error-page\.html$ [OR]
#RewriteCond %{REQUEST_URI} ^/errors/e404\.html$
#RewriteRule ^ - [L]
# presmerovani subdomeny s www na verzi bez www
RewriteCond %{HTTP_HOST} www\.(.*)\.([^\.]+)\.([^\.]*)$
RewriteRule (.*)$ http://%1.%2.%3/$1 [R=301,L,NE]
# presmerovani domeny 2. radu na verzi s www
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]*)$
RewriteRule (.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
# ochrana proti zacyklení
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
#kontrola existence subdomeny
RewriteCond %{HTTP_HOST} ^(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/%1_root !-d
RewriteRule ^ - [R=404,NC,L]
# presmerovani na verzi s lomitkem
RewriteCond %{HTTP_HOST} ^(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/%1_root/%{REQUEST_URI}/ -d
RewriteRule ^(.*)[^/]$ %{REQUEST_URI}/ [R=301,L,NE]
# podstrceni obsahu
RewriteCond %{HTTP_HOST} ^(.*)\.([^\.]*)\.([^\.]*)$
RewriteRule ^(.*)$ %1_root/$1 [L]
</IfModule>
@janpecha
Copy link
Author

janpecha commented Jul 2, 2013

Source code moved to GitHub repository - https://github.com/janpecha/htaccess-subdomains/

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