Project

General

Profile

« Previous | Next » 

Revision 8000

web/main/.htaccess: translate dotpaths to /-paths: Translate all .-separated components in the path to / instead of just those that exist in the filesystem. This allows per-source rules to match just a / for the path-element separator instead of sometimes / and other times . (depending on whether that portion of the dotpath had been translated). Support [] escapes that preserve any . they surround, e.g. a.[b.c] -> a/b.c . (Supporting []-escapes requires that the /-path be "sealed" by appending a / , to prevent the . -> / translation rule from reinterpreting a newly-unescaped [] sequence as a dotpath. This also requires that the translation rule ignore anything before the last /, because it could have been []-unescaped by a previous round of mod_rewrite, e.g. in another dir. All the per-source rules need to be retrofitted to support the new trailing / .) Note also the discardpath flag (http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_dpi) on all RewriteRules that perform a replacement on the input string (i.e. that have a pattern other than ^.*$). This flag is needed to avoid infinite loops, because otherwise, a critical bug in mod_rewrite causes it to reappend the filename portion of the input string (PATH_INFO) to the result, causing it to be present twice, e.g. a/b -> a/b/b (https://issues.apache.org/bugzilla/show_bug.cgi?id=38642).

View differences:

.htaccess
25 25
RewriteCond %{REQUEST_FILENAME} -l
26 26
RewriteRule ^.*$ - [last]
27 27

  
28
# translate dot-paths to dirs when they exist in the filesystem
29
# each subdir Redirect directive needs a corresponding tree of (empty) dirs
30
RewriteCond %{DOCUMENT_ROOT}/$1 -d [ornext]
31
RewriteCond %{DOCUMENT_ROOT}/$1 -l
32
RewriteRule ^([^.]*)\.(.*)$ $1/$2 [next]
33
	# next: if match, repeat until no more replacements
28
# translate dotpaths to /-paths (the dotpath follows the last /)
29
# replace all unescaped . with /
30
RewriteRule ^((?:.*/)?(?:[^.\[\]/]+|\[[^\[\]/]*\])+)\.([^/]+)$ $1/$2 [discardpath,next]
31
	# discardpath: avoids infinite loop with paths like a/b.c
32
# seal the /-path so the filename part is not reinterpreted as a dotpath
33
RewriteRule ^.*[^/]$ $0/
34
# remove all [] escapes (but leave empty [])
35
RewriteRule ^(.*)\[([^\[\]]+)\](.*)$ $1$2$3 [discardpath,next]
34 36

  
35 37
# non-filesystem paths
36 38
ErrorDocument 404 /

Also available in: Unified diff