Using placeholder in RewriteCond to be applied to RewriteRule - apache

I am using a placeholder in the RewriteCond which I expected to populate $1, and a second placeholder in the RewriteRule which I expected to populate $2.
It appears, however, that $1 is the placeholder set by the RewriteRule, and $2 is empty.
How can a placeholder be defined in the RewriteCond and applied to the RewriteRule?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.+).sites.example.com [NC]
RewriteRule ^public/(.+)$ public/$1/$2 [NC,L]
rewrite log:
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html -> public/xxx.html
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html' -> 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html/ -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (4) add subst prefix: public/xxx.html/ -> /public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html/ [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4547b8/initial/redir#1] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b459968/initial/redir#2] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b45eb88/initial/redir#3] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b463dd0/initial/redir#4] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b469218/initial/redir#5] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b46e628/initial/redir#6] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b473d88/initial/redir#7] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b4792d8/initial/redir#8] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b47f498/initial/redir#9] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (3) [perdir /var/www/mysite/html_sites/] add path info postfix: /var/www/mysite/html_sites/public/xxx.html -> /var/www/mysite/html_sites/public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/public/xxx.html/ -> public/xxx.html/
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'public/xxx.html/'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (4) [perdir /var/www/mysite/html_sites/] RewriteCond: input='test.sites.example.com' pattern='^(.+).sites.example.com' [NC] => matched
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (2) [perdir /var/www/mysite/html_sites/] rewrite 'public/xxx.html/' -> 'public/xxx.html//'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (3) [perdir /var/www/mysite/html_sites/] add per-dir prefix: public/xxx.html// -> /var/www/mysite/html_sites/public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (2) [perdir /var/www/mysite/html_sites/] trying to replace prefix /var/www/mysite/html_sites/ with /
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (5) strip matching prefix: /var/www/mysite/html_sites/public/xxx.html// -> public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (4) add subst prefix: public/xxx.html// -> /public/xxx.html//
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b484cb8/initial/redir#10] (1) [perdir /var/www/mysite/html_sites/] internal redirect with /public/xxx.html// [INTERNAL REDIRECT]
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (3) [perdir /var/www/mysite/html_sites/] strip per-dir prefix: /var/www/mysite/html_sites/favicon.ico -> favicon.ico
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (3) [perdir /var/www/mysite/html_sites/] applying pattern '^public/(.+)$' to uri 'favicon.ico'
[test.sites.example.com/sid#7f4a2b120f18][rid#7f4a2b43cbf8/initial] (1) [perdir /var/www/mysite/html_sites/] pass through /var/www/mysite/html_sites/favicon.ico

Placeholders for RewriteCond use % and placeholders for RewriteRule use $. Change to...
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.+).sites.example.com [NC]
RewriteRule ^public/(.+)$ public/%1/$1 [NC,L]

Related

How to solve Apache 2.4 mod_rewrite adding unnecessary and unwanted path info postfix?

Relevant parts of .htaccess: (all others commented out)
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteBase /somesite/
...
# All non-directory requests should go to /web/
RewriteCond %{REQUEST_URI} !/(web|cms|shared)/.*$
RewriteRule ^(.*)$ web/$1
...
# Language is irrelevant for resource passthrough. Strip it.
RewriteRule ^web/(en|nl)/(.*)$ web/$2
...
To keep the case simple, all unshown stuff is also commented out, so it does not affect the case.
Request:
http://some.domain.com/somesite/en/projecten/img/logo.png
Ends up:
http://some.domain.com/somesite/web/projecten/img/logo.png/projecten/img/logo.png
Though at this point, it should be:
http://some.domain.com/somesite/web/projecten/img/logo.png
In the logs, I traced the problem to a trace3 line stating add path info postfix:, which basically adds the unwanted part. This line is located directly after the first matching rewrite was performed. Everything happens within the same processing pass.
These are my only two rules that are chained, i.e. not final results and thus do not have the L-flag. This seems to be related to the problem.
Can someone enlighten me on what is happening, why, and an efficient solution?
Thanks in advance!
EDIT:
For the record the complete log related to this request:
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add path info postfix: /home/dev/domains/dev.company.nl/public_html/company_website/en -> /home/dev/domains/dev.company.nl/public_html/company_website/en/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] strip per-dir prefix: /home/dev/domains/dev.company.nl/public_html/company_website/en/projecten/img/company_logo.png -> en/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] applying pattern '^(.*)$' to uri 'en/projecten/img/company_logo.png'
[rewrite:trace4] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] RewriteCond: input='/company_website/en/projecten/img/company_logo.png' pattern='!/(web|cms|shared)/.*$' => matched
[rewrite:trace2] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] rewrite 'en/projecten/img/company_logo.png' -> 'web/en/projecten/img/company_logo.png'
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add per-dir prefix: web/en/projecten/img/company_logo.png -> /home/dev/domains/dev.company.nl/public_html/company_website/web/en/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add path info postfix: /home/dev/domains/dev.company.nl/public_html/company_website/web/en/projecten/img/company_logo.png -> /home/dev/domains/dev.company.nl/public_html/company_website/web/en/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] strip per-dir prefix: /home/dev/domains/dev.company.nl/public_html/company_website/web/en/projecten/img/company_logo.png/projecten/img/company_logo.png -> web/en/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] applying pattern '^web/(en|nl)/(.*)$' to uri 'web/en/projecten/img/company_logo.png/projecten/img/company_logo.png'
[rewrite:trace2] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] rewrite 'web/en/projecten/img/company_logo.png/projecten/img/company_logo.png' -> 'web/projecten/img/company_logo.png/projecten/img/company_logo.png'
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add per-dir prefix: web/projecten/img/company_logo.png/projecten/img/company_logo.png -> /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace2] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] trying to replace prefix /home/dev/domains/dev.company.nl/public_html/company_website/ with /company_website/
[rewrite:trace5] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] strip matching prefix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png -> web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace4] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] add subst prefix: web/projecten/img/company_logo.png/projecten/img/company_logo.png -> /company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace1] - - [dev.company.nl/sid#17962b0][rid#1a88ce0/initial] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] internal redirect with /company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png [INTERNAL REDIRECT]
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add path info postfix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten -> /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] strip per-dir prefix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png -> web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] applying pattern '^(.*)$' to uri 'web/projecten/img/company_logo.png/projecten/img/company_logo.png'
[rewrite:trace4] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] RewriteCond: input='/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png' pattern='!/(web|cms|shared)/.*$' => not-matched
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] add path info postfix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten -> /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] strip per-dir prefix: /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten/img/company_logo.png/projecten/img/company_logo.png -> web/projecten/img/company_logo.png/projecten/img/company_logo.png
[rewrite:trace3] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] applying pattern '^web/(en|nl)/(.*)$' to uri 'web/projecten/img/company_logo.png/projecten/img/company_logo.png'
[rewrite:trace1] - - [dev.company.nl/sid#17962b0][rid#1a95a20/initial/redir#1] [perdir /home/dev/domains/dev.company.nl/public_html/company_website/] pass through /home/dev/domains/dev.company.nl/public_html/company_website/web/projecten

Restler not loading any classes

Using Restler 3.0.0-RC6 I'm getting a 404 from Routes.php at route stage. I've turned on rewrite debugging on apache and I see that it's redirecting to /var/www/html/api/public/index.php when I try to load the URL, and that is in fact where the index.php for Restler lives. It's just not loading any of the classes from the src directory though. How do I debug this?
Here's the rewrite rule output:
[perdir /var/www/html/api/] add path info postfix: /var/www/html/api/v2 -> /var/www/html/api/v2/team/details/1/0
[perdir /var/www/html/api/] strip per-dir prefix: /var/www/html/api/v2/team/details/1/0 -> v2/team/details/1/0
[perdir /var/www/html/api/] applying pattern '^$' to uri 'v2/team/details/1/0'
[perdir /var/www/html/api/] add path info postfix: /var/www/html/api/v2 -> /var/www/html/api/v2/team/details/1/0
[perdir /var/www/html/api/] strip per-dir prefix: /var/www/html/api/v2/team/details/1/0 -> v2/team/details/1/0
[perdir /var/www/html/api/] applying pattern '^(.*)$' to uri 'v2/team/details/1/0'
[perdir /var/www/html/api/] RewriteCond: input='/var/www/html/api/v2' pattern='!-f' => matched
[perdir /var/www/html/api/] RewriteCond: input='/var/www/html/api/v2' pattern='!-d' => matched
[perdir /var/www/html/api/] rewrite 'v2/team/details/1/0' -> 'public/index.php'
[perdir /var/www/html/api/] add per-dir prefix: public/index.php -> /var/www/html/api/public/index.php
[perdir /var/www/html/api/] strip document_root prefix: /var/www/html/api/public/index.php -> /api/public/index.php
[perdir /var/www/html/api/] internal redirect with /api/public/index.php [INTERNAL REDIRECT]
[perdir /var/www/html/api/public/] strip per-dir prefix: /var/www/html/api/public/index.php -> index.php
[perdir /var/www/html/api/public/] applying pattern '^' to uri 'index.php'
[perdir /var/www/html/api/public/] RewriteCond: input='/var/www/html/api/public/index.php' pattern='!-d' => matched
[perdir /var/www/html/api/public/] RewriteCond: input='/var/www/html/api/public/index.php' pattern='!-f' => not-matched
[perdir /var/www/html/api/public/] pass through /var/www/html/api/public/index.php
And as you can see, the index.php is there, and the appropriate class is there:
% ls -l /var/www/html/api/public/index.php
-rw-r--r-- 1 root root 961 Jun 3 21:40 /var/www/html/api/public/index.php
% ls -l /var/www/html/api/src/v2/Team.php
-rw-rwxr-- 1 559 559 19255 May 9 23:02 /var/www/html/api/src/v2/Team.php
I forgot to include the Defaults::$useUrlBasedVersioning = true; line in my index.php so it was always trying to force a v1 version to load, which doesn't exist any longer.

internal mod_rewrite leads to infinite redirects

I have a server on localhost:8080 and I've piped requests to it via a tunneling software called ngrok so now I want to setup my mod_rewrite policy to map and serve any request from mysubdomain.ngrok.com to localhost:8080 without redirecting the browser.
# Turn on rewrites
RewriteEngine on
###
## Rules for "mysubdomain.ngrok.com"
###
RewriteCond %{HTTP_HOST} ^mysubdomain.ngrok.com$
RewriteRule .? %{REQUEST_URI} [L]
###
## Rules for "localhost:8080"
###
RewriteCond %{HTTP_HOST} ^localhost:8080$
RewriteRule . - [E=REWRITEBASE:/prestashop/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
But I end up in infinite redirect loop! What's the best way to avoid this and accomplish my goal?
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] add path info postfix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api -> /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] strip per-dir prefix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products -> api/products
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] applying pattern '.?' to uri 'api/products'
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] RewriteCond: input='mysubdomain.ngrok.com' pattern='^mysubdomain.ngrok.com$' => matched
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] rewrite 'api/products' -> '/prestashop/api/products'
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] internal redirect with /prestashop/api/products [INTERNAL REDIRECT]
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] add path info postfix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api -> /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] strip per-dir prefix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products -> api/products
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] applying pattern '.?' to uri 'api/products'
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] RewriteCond: input='mysubdomain.ngrok.com' pattern='^mysubdomain.ngrok.com$' => matched
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] rewrite 'api/products' -> '/prestashop/api/products'
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] internal redirect with /prestashop/api/products [INTERNAL REDIRECT]
...
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] add path info postfix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api -> /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] strip per-dir prefix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products -> api/products
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] applying pattern '.?' to uri 'api/products'
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] RewriteCond: input='mysubdomain.ngrok.com' pattern='^mysubdomain.ngrok.com$' => matched
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] rewrite 'api/products' -> '/prestashop/api/products'
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] internal redirect with /prestashop/api/products [INTERNAL REDIRECT]
Looking at logs and rules I can see that this rule is causing infinite looping:
RewriteCond %{HTTP_HOST} ^mysubdomain.ngrok.com$
RewriteRule .? %{REQUEST_URI} [L]
As it is unconditionally writing a URI to itself for domain=mysubdomain.ngrok.com
Just comment it out and looping will be fixed.

Difference in .htaccess behaviour

I have finished developing a micro app with Phalcon and tried to move it to production server, but have encountered some problems with .htaccess rules.
Directory layout on the serwer is like this :
/var/www
|- .htaccess
|- redmine/
|- wordpress/
|- (other dirs)
|- MyApp/
|- .htaccess
|- public/
|- .htaccess
|- api.php
/var/www/.htaccess :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !(redmine|MyApp) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
/var/www/MyApp/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png|\.mp3|\.ods|\.csv|\.xls)$ [NC]
RewriteRule ^$ public/ [L]
RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png|\.mp3|\.ods|\.csv|\.xls)$ [NC]
RewriteRule (.*) public/$1 [L]
</IfModule>
/var/www/MyApp/public/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ api.php?_url=/$1 [QSA,L]
</IfModule>
I'm really new to all this. The top-most .htaccess was not setup by me, and frankly I don't know what is going on in there. The others are based on Phalcon tutorials.
Everything worked on my local machine, but stopped when I uploaded it. I turned on logging in both places.
Local log :
[perdir /Users/Losiowaty/MyApp/] add path info postfix: /Users/Losiowaty/MyApp/api -> /Users/Losiowaty/MyApp/api/poeci
[perdir /Users/Losiowaty/MyApp/] strip per-dir prefix: /Users/Losiowaty/MyApp/api/poeci -> api/poeci
[perdir /Users/Losiowaty/MyApp/] applying pattern '^$' to uri 'api/poeci'
[perdir /Users/Losiowaty/MyApp/] add path info postfix: /Users/Losiowaty/MyApp/api -> /Users/Losiowaty/MyApp/api/poeci
[perdir /Users/Losiowaty/MyApp/] strip per-dir prefix: /Users/Losiowaty/MyApp/api/poeci -> api/poeci
[perdir /Users/Losiowaty/MyApp/] applying pattern '(.*)' to uri 'api/poeci'
[perdir /Users/Losiowaty/MyApp/] RewriteCond: input='/MyApp/api/poeci' pattern='!(\\.gif|\\.jpg|\\.png|\\.mp3|\\.ods|\\.csv|\\.xls)$' [NC] => matched
[perdir /Users/Losiowaty/MyApp/] rewrite 'api/poeci' -> 'public/api/poeci'
[perdir /Users/Losiowaty/MyApp/] add per-dir prefix: public/api/poeci -> /Users/Losiowaty/MyApp/public/api/poeci
[perdir /Users/Losiowaty/MyApp/] strip document_root prefix: /Users/Losiowaty/MyApp/public/api/poeci -> /MyApp/public/api/poeci
[perdir /Users/Losiowaty/MyApp/] internal redirect with /MyApp/public/api/poeci [INTERNAL REDIRECT]
[perdir /Users/Losiowaty/MyApp/public/] add path info postfix: /Users/Losiowaty/MyApp/public/api -> /Users/Losiowaty/MyApp/public/api/poeci
[perdir /Users/Losiowaty/MyApp/public/] strip per-dir prefix: /Users/Losiowaty/MyApp/public/api/poeci -> api/poeci
[perdir /Users/Losiowaty/MyApp/public/] applying pattern '^(.*)$' to uri 'api/poeci'
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api' pattern='!-d' => matched
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api' pattern='!-f' => matched
[perdir /Users/Losiowaty/MyApp/public/] rewrite 'api/poeci' -> 'api.php?_url=/api/poeci'
split uri=api.php?_url=/api/poeci -> uri=api.php, args=_url=/api/poeci
[perdir /Users/Losiowaty/MyApp/public/] add per-dir prefix: api.php -> /Users/Losiowaty/MyApp/public/api.php
[perdir /Users/Losiowaty/MyApp/public/] strip document_root prefix: /Users/Losiowaty/MyApp/public/api.php -> /MyApp/public/api.php
[perdir /Users/Losiowaty/MyApp/public/] internal redirect with /MyApp/public/api.php [INTERNAL REDIRECT]
[perdir /Users/Losiowaty/MyApp/public/] strip per-dir prefix: /Users/Losiowaty/MyApp/public/api.php -> api.php
[perdir /Users/Losiowaty/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php'
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api.php' pattern='!-d' => matched
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api.php' pattern='!-f' => not-matched
[perdir /Users/Losiowaty/MyApp/public/] pass through /Users/Losiowaty/MyApp/public/api.php
Remote log :
[perdir /var/www/MyApp/] add path info postfix: /var/www/MyApp/api -> /var/www/MyApp/api/poeci
[perdir /var/www/MyApp/] strip per-dir prefix: /var/www/MyApp/api/poeci -> api/poeci
[perdir /var/www/MyApp/] applying pattern '^$' to uri 'api/poeci'
[perdir /var/www/MyApp/] add path info postfix: /var/www/MyApp/api -> /var/www/MyApp/api/poeci
[perdir /var/www/MyApp/] strip per-dir prefix: /var/www/MyApp/api/poeci -> api/poeci
[perdir /var/www/MyApp/] applying pattern '(.*)' to uri 'api/poeci'
[perdir /var/www/MyApp/] RewriteCond: input='/MyApp/api/poeci' pattern='!(\\.gif|\\.jpg|\\.png|\\.mp3|\\.ods|\\.csv|\\.xls)$' [NC] => matched
[perdir /var/www/MyApp/] rewrite 'api/poeci' -> 'public/api/poeci'
[perdir /var/www/MyApp/] add per-dir prefix: public/api/poeci -> /var/www/MyApp/public/api/poeci
[perdir /var/www/MyApp/] strip document_root prefix: /var/www/MyApp/public/api/poeci -> /MyApp/public/api/poeci
[perdir /var/www/MyApp/] internal redirect with /MyApp/public/api/poeci [INTERNAL REDIRECT]
[perdir /var/www/MyApp/public/] add path info postfix: /var/www/MyApp/public/api.php -> /var/www/MyApp/public/api.php/poeci
[perdir /var/www/MyApp/public/] strip per-dir prefix: /var/www/MyApp/public/api.php/poeci -> api.php/poeci
[perdir /var/www/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php/poeci'
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-d' => matched
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-f' => not-matched
[perdir /var/www/MyApp/public/] pass through /var/www/MyApp/public/api.php
[perdir /var/www/MyApp/public/] add path info postfix: /var/www/MyApp/public/api.php -> /var/www/MyApp/public/api.php/poeci
[perdir /var/www/MyApp/public/] strip per-dir prefix: /var/www/MyApp/public/api.php/poeci -> api.php/poeci
[perdir /var/www/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php/poeci'
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-d' => matched
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-f' => not-matched
[perdir /var/www/MyApp/public/] pass through /var/www/MyApp/public/api.php
[perdir /var/www/] strip per-dir prefix: /var/www/poeci -> poeci
[perdir /var/www/] applying pattern '^index\\.php$' to uri 'poeci'
[perdir /var/www/] strip per-dir prefix: /var/www/poeci -> poeci
[perdir /var/www/] applying pattern '.' to uri 'poeci'
[perdir /var/www/] RewriteCond: input='/poeci' pattern='!(redmine|MyApp)' [NC] => matched
[perdir /var/www/] RewriteCond: input='/var/www/poeci' pattern='!-f' => matched
[perdir /var/www/] RewriteCond: input='/var/www/poeci' pattern='!-d' => matched
[perdir /var/www/] rewrite 'poeci' -> '/index.php'
[perdir /var/www/] trying to replace prefix /var/www/ with /
[perdir /var/www/] internal redirect with /index.php [INTERNAL REDIRECT]
The differences begin with the first line with [perdir (...)] ending with /public/. I don't understand why it adds .php and why the !-f rule doesn't match on the remote server.
Local server :
OSX 10.9.3, MAMP 3.0.4, Apache 2.2.26
Remote server :
Debian GNU/Linux 6.0.9, Apache 2.2.16
I wonder whether this is caused by the additional .htaccess file on the remote, or by the difference in Apache version.
I'd appreciate some explanation as to what's going on and any directions on where to look for answers.
Cheers!
This looks like it may be caused by multiviews. In both htaccess files inside MyApp, add this (above your rules, but anywhere is fine):
Options -Multiviews
Note that because api.php exists, a PATH INFO url like: /MyApp/api.php/something will fail the !-f check.

adding index.cfm to url seems to ignore .htaccess

I'm trying to disallow access to certain folders in my webApp, but there seems to be some exception to the use of index.cfm somewhere...
for this example I'm using just the folllowing mod_rewrite rule:
RewriteRule ^(.*)$ index.cfm [QSA,L]
accessing the following urls with results:
/index.cfm //->/index.cfm naturally
/test/test.html //->/index.cfm
/test/ //->/index.cfm
/test/test.cfm //->/index.cfm
/test/index.cfm //->/test/index.cfm
Note that the last request seems to ignore the rewrite rule, how could that happen?
(All files above are not present in the file system with exception to the index.cfm in the root)
EDIT also, the .htaccess file is placed in the root directory
EDIT 2 I added a RewriteLog to see whats going on, There definitely is a difference but I dont see why...
/test/index.html
[rid#15d1048/initial] (2) init rewrite engine with requested uri /test/index.html
[rid#15d1048/initial] (1) pass through /test/index.html
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] add path info postfix: C:/my/local/dir/test -> C:/my/local/dir/test/index.html
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] strip per-dir prefix: C:/my/local/dir/test/index.html -> test/index.html
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] applying pattern '^(.*)$' to uri 'test/index.html'
[rid#15d1048/initial] (2) [perdir C:/my/local/dir/] rewrite 'test/index.html' -> 'index.cfm'
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] add per-dir prefix: index.cfm -> C:/my/local/dir/index.cfm
[rid#15d1048/initial] (2) [perdir C:/my/local/dir/] strip document_root prefix: C:/my/local/dir/index.cfm -> /index.cfm
[rid#15d1048/initial] (1) [perdir C:/my/local/dir/] internal redirect with /index.cfm [INTERNAL REDIRECT]
[rid#15cb4c0/initial/redir#1] (2) init rewrite engine with requested uri /index.cfm
[rid#15cb4c0/initial/redir#1] (1) pass through /index.cfm
[rid#15cb4c0/initial/redir#1] (3) [perdir C:/my/local/dir/] strip per-dir prefix: C:/my/local/dir/index.cfm -> index.cfm
[rid#15cb4c0/initial/redir#1] (3) [perdir C:/my/local/dir/] applying pattern '^(.*)$' to uri 'index.cfm'
[rid#15cb4c0/initial/redir#1] (2) [perdir C:/my/local/dir/] rewrite 'index.cfm' -> 'index.cfm'
[rid#15cb4c0/initial/redir#1] (3) [perdir C:/my/local/dir/] add per-dir prefix: index.cfm -> C:/my/local/dir/index.cfm
[rid#15cb4c0/initial/redir#1] (1) [perdir C:/my/local/dir/] initial URL equal rewritten URL: C:/my/local/dir/index.cfm [IGNORING REWRITE]
/test/index.cfm
[rid#15ca1a0/initial] (2) init rewrite engine with requested uri /test/index.cfm
[rid#15ca1a0/initial] (1) pass through /test/index.cfm
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] add path info postfix: C:/my/local/dir/test -> C:/my/local/dir/test/index.cfm
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] strip per-dir prefix: C:/my/local/dir/test/index.cfm -> test/index.cfm
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] applying pattern '^(.*)$' to uri 'test/index.cfm'
[rid#15ca1a0/initial] (2) [perdir C:/my/local/dir/] rewrite 'test/index.cfm' -> 'index.cfm'
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] add per-dir prefix: index.cfm -> C:/my/local/dir/index.cfm
[rid#15ca1a0/initial] (2) [perdir C:/my/local/dir/] strip document_root prefix: C:/my/local/dir/index.cfm -> /index.cfm
[rid#15ca1a0/initial] (1) [perdir C:/my/local/dir/] internal redirect with /index.cfm [INTERNAL REDIRECT]
Not the perfect answer i was looking for but this is what I did to get the same result:
In the .htaccess I add the following line to forward any files not processed by railo:
RewriteCond %{REQUEST_URI} ^/(my|forbidden|folders)
RewriteRule ^(.*)$ /index.cfm/some/page [L]
In the application.cfc I add the following line to forward the files processed by railo:
<cfif Find(listFirst(arguments.targetPage, "/"), "my,forbidden,folders")>
<cfset GetPageContext().Forward("/index.cfm/some/page")>
</cfif>
This way I can show another page whilst not changing the requested url.
I was hoping for a solution just in the .htaccess but it seems because of a bug in the resin / apache connection this cannot work yet.