Project

General

Profile

1
#### URL resolution
2

    
3
DirectorySlash on
4
DirectoryIndex index.php
5

    
6
### mod_rewrite
7

    
8
RewriteEngine on
9

    
10
# remove www subdomain
11
RewriteCond %{HTTP_HOST} ^www\.(.*)$
12
RewriteRule ^.*$ http://%1/$0 [redirect]
13

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

    
21
# don't rewrite existing paths
22
RewriteCond %{REQUEST_FILENAME} -d [ornext]
23
RewriteCond %{REQUEST_FILENAME} -f [ornext]
24
RewriteCond %{REQUEST_FILENAME} -l
25
RewriteRule ^.*$ - [last]
26

    
27
## translate dotpaths (after the last /) to /-paths, e.g. d/a.[b.c] -> d/a/b.c/
28

    
29
# replace all unescaped . with / , e.g. a.[b.c] -> a/[b.c]
30
RewriteRule ^((?:.*/)?(?:[^.\[\]/]+|\[[^\[\]/]*\])+)\.([^/]+)$ $1/$2 [discardpath,next]
31
	# discardpath: avoids infinite loop with paths like a/b.c
32

    
33
# seal the /-path so the filename part is not reinterpreted as a dotpath
34
# e.g. a/[b.c] -> a/[b.c]/ so it doesn't become a/b/c after []-unescaping
35
# this is needed because mod_rewrite often runs the same rules again
36
RewriteRule ^.*[^/]$ $0/
37

    
38
# remove all [] escapes (but leave empty []), e.g. a/[b.c]/ -> a/b.c/
39
RewriteRule ^(.*)\[([^\[\]]+)\](.*)$ $1$2$3 [discardpath,next]
40

    
41

    
42
# non-filesystem paths
43
ErrorDocument 404 /
(1-1/5)