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 |
8010
|
aaronmk
|
RewriteOptions inherit
|
10 |
7876
|
aaronmk
|
|
11 |
7959
|
aaronmk
|
# remove www subdomain
|
12 |
|
|
RewriteCond %{HTTP_HOST} ^www\.(.*)$
|
13 |
8013
|
aaronmk
|
RewriteRule ^.*$ http://%1/$0 [discardpath,noescape,last]
|
14 |
7959
|
aaronmk
|
|
15 |
7987
|
aaronmk
|
# 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 |
8011
|
aaronmk
|
RewriteRule ^.*$ %0/$0 [discardpath,noescape,last]
|
21 |
7987
|
aaronmk
|
|
22 |
7997
|
aaronmk
|
# don't rewrite existing paths
|
23 |
|
|
RewriteCond %{REQUEST_FILENAME} -d [ornext]
|
24 |
|
|
RewriteCond %{REQUEST_FILENAME} -f [ornext]
|
25 |
|
|
RewriteCond %{REQUEST_FILENAME} -l
|
26 |
8011
|
aaronmk
|
RewriteRule ^.*$ - [discardpath,noescape,last]
|
27 |
7997
|
aaronmk
|
|
28 |
8001
|
aaronmk
|
## translate dotpaths (after the last /) to /-paths, e.g. d/a.[b.c] -> d/a/b.c/
|
29 |
|
|
|
30 |
|
|
# replace all unescaped . with / , e.g. a.[b.c] -> a/[b.c]
|
31 |
8015
|
aaronmk
|
RewriteRule ^((?:.*/)?(?:[^.\[\]/]*|\[[^\[\]/]*\])*)\.([^/]*)$ $1/$2 [discardpath,noescape,next]
|
32 |
8000
|
aaronmk
|
# discardpath: avoids infinite loop with paths like a/b.c
|
33 |
8001
|
aaronmk
|
|
34 |
8000
|
aaronmk
|
# seal the /-path so the filename part is not reinterpreted as a dotpath
|
35 |
8001
|
aaronmk
|
# e.g. a/[b.c] -> a/[b.c]/ so it doesn't become a/b/c after []-unescaping
|
36 |
|
|
# this is needed because mod_rewrite often runs the same rules again
|
37 |
8011
|
aaronmk
|
RewriteRule ^.*[^/]$ $0/ [discardpath,noescape]
|
38 |
8001
|
aaronmk
|
|
39 |
8014
|
aaronmk
|
# remove all [] escapes, e.g. a/[b.c]/ -> a/b.c/
|
40 |
|
|
RewriteRule ^(.*)\[([^\[\]]*)\](.*)$ $1$2$3 [discardpath,noescape,next]
|
41 |
7970
|
aaronmk
|
|
42 |
8001
|
aaronmk
|
|
43 |
7957
|
aaronmk
|
# non-filesystem paths
|
44 |
7973
|
aaronmk
|
ErrorDocument 404 /
|