Project

General

Profile

« Previous | Next » 

Revision 8363

web/main/**/.htaccess: Support dotpaths in the query string instead of in the path, so that non-dotpath paths don't need to be suffixed with / to prevent their filenames from being interpreted as dotpaths. Putting dotpaths in the query string still requires only one character between the host and the path, but it's ? instead of / . ? is in many ways more natural, because the dotpath is a non-filesystem string to be parsed rather than something that's already a filesystem path. This change also avoids the need to strip trailing /s in many RewriteRules, because the dotpath mechanism is no longer appending them.

View differences:

.htaccess
28 28
RewriteCond %{DOCUMENT_ROOT}/%0 -d
29 29
RewriteRule ^([^/]*)(/.*)$ %0$2 [discardpath,noescape]
30 30

  
31
# don't rewrite existing paths
32
RewriteCond %{REQUEST_FILENAME} -d [ornext]
33
RewriteCond %{REQUEST_FILENAME} -f
34
RewriteRule ^.*$ - [discardpath,noescape,last]
31
# parse dotpath in the query string
32
RewriteRule ^dotpath - [discardpath,noescape,last]
33
RewriteCond %{QUERY_STRING} ^(?!&).+$
34
RewriteRule ^.*$ /dotpath.php%{REQUEST_URI} [discardpath,noescape,last]
35 35

  
36 36
# don't redirect subdir paths
37 37
RewriteCond %{DOCUMENT_ROOT}/$1 -d
38 38
RewriteRule ^([^/]+).*$ - [discardpath,noescape,last]
39 39

  
40
# handle DirectoryIndex (this must be at this position in the rules)
41
RewriteRule ^(.*/)?index\.php$ $1 [discardpath,noescape]
40
# don't rewrite existing paths
41
RewriteCond %{REQUEST_FILENAME} -d [ornext]
42
RewriteCond %{REQUEST_FILENAME} -f
43
RewriteRule ^.*$ - [discardpath,noescape,last]
42 44

  
43
## translate dotpaths (after the last /) to /-paths, e.g. d/a.[b.c] -> d/a/b.c/
44
# replace all unescaped . with / , e.g. a.[b.c] -> a/[b.c]
45
# remove any [] escape, e.g. a.b=[c.d] -> a/b=c.d (the ] must be at the end)
46
# if no . suffix, seal /-path so the filename is not reinterpreted as a dotpath
47
# e.g. a/[b.c] -> a/[b.c]/ so it doesn't become a/b/c after []-unescaping
48
# this is needed because mod_rewrite often runs the same rules again
49
RewriteRule ^(.*/)?(?=.)(\.?[^./]*?)(?:\[([^\[\]/]*)\])?(?:\.([^/]*))?$ $1$2$3/$4 [discardpath,noescape,next]
50
	# discardpath: avoids infinite loop by not reappending PATH_INFO (filename)
51

  
52 45
## specific to /
53 46

  
54
RewriteRule ^(?:(.*)/)?$ https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#$1 [discardpath,noescape,last]
47
RewriteRule ^.*$ https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore#$0 [discardpath,noescape,last]

Also available in: Unified diff