Project

General

Profile

1 7876 aaronmk
#### URL resolution
2
3 7889 aaronmk
DirectorySlash on
4 7949 aaronmk
DirectoryIndex index.php
5 7876 aaronmk
6
### mod_rewrite
7
8 7878 aaronmk
RewriteEngine on
9 7876 aaronmk
10 7959 aaronmk
# remove www subdomain
11
RewriteCond %{HTTP_HOST} ^www\.(.*)$
12
RewriteRule ^.*$ http://%1/$0 [redirect]
13
14 7987 aaronmk
# 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 7997 aaronmk
# 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 8001 aaronmk
## 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 8000 aaronmk
RewriteRule ^((?:.*/)?(?:[^.\[\]/]+|\[[^\[\]/]*\])+)\.([^/]+)$ $1/$2 [discardpath,next]
31
	# discardpath: avoids infinite loop with paths like a/b.c
32 8001 aaronmk
33 8000 aaronmk
# seal the /-path so the filename part is not reinterpreted as a dotpath
34 8001 aaronmk
# 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 8000 aaronmk
RewriteRule ^.*[^/]$ $0/
37 8001 aaronmk
38
# remove all [] escapes (but leave empty []), e.g. a/[b.c]/ -> a/b.c/
39 8000 aaronmk
RewriteRule ^(.*)\[([^\[\]]+)\](.*)$ $1$2$3 [discardpath,next]
40 7970 aaronmk
41 8001 aaronmk
42 7957 aaronmk
# non-filesystem paths
43 7973 aaronmk
ErrorDocument 404 /