In my Zend project, I came across almost the same htaccess file, and here are my thoughts and hope this helps.
The htaccess file (located in the Zend project directory, same as index.php) says
RewriteCond% {REQUEST_URI} :: $ 1 ^ (/.+) (. +) :: \ 2 $
RewriteRule ^ (. *) $ - [E = BASE:% 1]
RewriteRule ^ (. *) $% {ENV: BASE} index.php [NC, L]
Suppose Zend is installed at http://mydomain.com/zend (let it rename it later) and we request yourdomain / mycontroller / myaction
Therefore,% {REQUEST_URI} will be "/ zend / mycontroller / myaction".
Note that $ 1, which is a template in the RewriteRule directive in the context of htaccess [1], "will initially be mapped to the file path, after removing the prefix that led the server to the current RewriteRule (for example," app1 / index.html "or" index .html "depending on where the directives are defined).
Therefore, $ 1 will be "mycontroller / myaction".
And% {REQUEST_URI} :: $ 1 will be "/ zend / mycontroller / myaction :: mycontroller / myaction".
The above line will be matched with ^ (/.+) (. +) :: \ 2 $. Please note that for two gripping groups in parentheses, i.e. (/.+) (. +) to :: many combinations can match this. For instance:
Group 1: / z
Group 2: end / mycontroller / myaction
or
Group 1: / zend / mycontroller / myactio
Group 2: n
and everything in between is a valid coincidence. In fact, the most interesting will be
Group 1: / zend /
Group 2: mycontroller / myaction
which (is the only case) makes a backward link \ 2 (after: :) matches the second group.
In this case, "/ zend /" will be stored in the BASE environment variable, which is what the first RewriteRule does. % 1 refers to the first matched line in the RewriteCond, which is "/ zend /".
Looking at the second RewriteRule, it is clear why this is necessary. Since index.php can only be found in /zend/index.php, we need to add "/ zend /" before index.php.
Here we intend to use the URL path as a substitute for the second RewriteRule directive. Refer to [1] and find the "relative path of the DocumentRoot to the resource that will be served" in the "RewriteRule Directive" section.
All of the above leaves the query string unchanged / untouched. It depends on index.php how to parse the query string (as well as the URI).
Finally, there comes the case when Zend is installed in the root of the domain.
% {REQUEST_URI} will be "/ mycontroller / myaction". $ 1 will be "mycontroller / myaction".
The line that will match the RewriteCond will be "/ mycontroller / myaction :: mycontroller / myaction".
This time, the second group in (/.+)(.+) will never match "mycontroller / myaction" since there must be at least one letter after the initial backslash for the first group, which makes the second group closed as "ycontroller / myaction ", but not exactly" mycontroller / myaction ", so there can be no match.
As a result, the first RewriteRule is not used. The BASE enviornment variable will not be set, and when the second RewriteRule uses it, it will simply be empty.
References
[1] http://httpd.apache.org/docs/current/mod/mod_rewrite.html