Project

General

Profile

« Previous | Next » 

Revision 7987

web/vegpath/.htaccess: translate subdomain to path: Simplified using new subdomain2path RewriteMap, which avoids the need for a separate RewriteRule+RewriteConds for each number of nested subdomains

View differences:

.htaccess
12 12
RewriteCond %{HTTP_HOST} ^www\.(.*)$
13 13
RewriteRule ^.*$ http://%1/$0 [redirect]
14 14

  
15
# translate subdomain to path
16
RewriteCond expr "%{HTTP_HOST} != %{SERVER_NAME}"
17
RewriteCond %{HTTP_HOST} ^(.*)(\.[^.]*){2}$
18
RewriteCond ${subdomain2path:%1} ^([^/]*).*$
19
RewriteCond expr "! $0 -fnmatch '%1*'"
20
RewriteRule ^.*$ %0/$0 [last]
21

  
15 22
# don't rewrite existing paths
16 23
RewriteCond %{REQUEST_FILENAME} -d [ornext]
17 24
RewriteCond %{REQUEST_FILENAME} -f [ornext]
18 25
RewriteCond %{REQUEST_FILENAME} -l
19 26
RewriteRule ^.*$ - [last]
20 27

  
21
# translate 2-level subdomain to prefix
22
RewriteCond %{HTTP_HOST} ^([^.]*)\.([^.]*)\..*$
23
RewriteCond %{DOCUMENT_ROOT}/%2/%1 -d [ornext]
24
RewriteCond %{DOCUMENT_ROOT}/%2/%1 -l
25
# this RewriteRule won't be re-run
26
RewriteCond %{DOCUMENT_ROOT}/%2/%1/.htaccess -f
27
RewriteRule ^.*$ %2/%1/$0 [last,nosubreq] # avoid infinite recursion
28

  
29
# translate 1-level subdomain to prefix
30
RewriteCond %{HTTP_HOST} ^([^.]*)\..*$
31
RewriteCond %{DOCUMENT_ROOT}/%1 -d [ornext]
32
RewriteCond %{DOCUMENT_ROOT}/%1 -l
33
# this RewriteRule won't be re-run
34
RewriteCond %{DOCUMENT_ROOT}/%1/.htaccess -f
35
RewriteRule ^.*$ %1/$0 [last,nosubreq] # avoid infinite recursion
36

  
37 28
# translate dot-paths to dirs
38 29
RewriteCond %{DOCUMENT_ROOT}/$1 -d [ornext]
39 30
RewriteCond %{DOCUMENT_ROOT}/$1 -l

Also available in: Unified diff