.htaccess - Apache rewrite parses URL twice unexpectedly -


i'm trying redirect webpages domain names specific web application handles several sites. have web app in folder "skylight2" , folder, named "testsite", .htaccess file:

rewriteengine on rewriterule ^(((?!skylight2).)*)$ /home/stefano/webroot_aliases/skylight2/$1/?site=testsite [qsa] 

i'm using virtual roots, , httpd-vroot.conf looks this:

<virtualhost *:80>         servername webserver         serveralias *.webserver          usecanonicalname off         virtualdocumentroot /home/stefano/webroot_aliases/%1          options -indexes followsymlinks -multiviews         rewritelog "/var/log/httpd/vroot_rewrite.log"         rewriteloglevel 3          <directory /home/stefano/webroot_aliases/>                 order allow,deny                 allow                 allowoverride fileinfo indexes limit options                  rewriteengine on                 rewritebase /          </directory> </virtualhost> 

if try access testsite.webserver, "object not found" error. rewrite log:

127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/articles -> /home/stefano/webroot_aliases/testsite/articles/view 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/articles/view -> articles/view 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(((?!skylight2).)*)$' uri 'articles/view' 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'articles/view' -> '/home/stefano/webroot_aliases/skylight2/articles/view/?site=testsite' 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (3) split uri=/home/stefano/webroot_aliases/skylight2/articles/view/?site=testsite -> uri=/home/stefano/webroot_aliases/skylight2/articles/view/, args=site=testsite 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect /home/stefano/webroot_aliases/skylight2/articles/view/ [internal redirect] 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2531a18/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/home -> /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/skylight2/articles/view/ 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2531a18/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/skylight2/articles/view/ -> home/stefano/webroot_aliases/skylight2/articles/view/ 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2531a18/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(((?!skylight2).)*)$' uri 'home/stefano/webroot_aliases/skylight2/articles/view/' 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2531a18/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] pass through /home/stefano/webroot_aliases/testsite/home 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/favicon.ico -> favicon.ico 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(((?!skylight2).)*)$' uri 'favicon.ico' 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'favicon.ico' -> '/home/stefano/webroot_aliases/skylight2/favicon.ico/?site=testsite' 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (3) split uri=/home/stefano/webroot_aliases/skylight2/favicon.ico/?site=testsite -> uri=/home/stefano/webroot_aliases/skylight2/favicon.ico/, args=site=testsite 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect /home/stefano/webroot_aliases/skylight2/favicon.ico/ [internal redirect] 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2533830/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/home -> /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/skylight2/favicon.ico/ 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2533830/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/skylight2/favicon.ico/ -> home/stefano/webroot_aliases/skylight2/favicon.ico/ 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2533830/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(((?!skylight2).)*)$' uri 'home/stefano/webroot_aliases/skylight2/favicon.ico/' 127.0.0.1 - - [08/mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2533830/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] pass through /home/stefano/webroot_aliases/testsite/home 

apparently, url parsed once (correctly), , second time it's added prefix again, resulting in error. unfortunately, cannot put [l] flag rule because url gets parsed further in application folder. can explain me happening?

thanks

gm

edit: applied rule:

rewriterule ^(?!skylight2)(.*)$ skylight2/$1/?site=testsite [qsa,l] 

and this:

127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_a liases/testsite/articles -> /home/stefano/webroot_aliases/testsite/articles/view 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_al iases/testsite/articles/view -> articles/view 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' uri  'articles/view' 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'articles/view' -> 'skylight2/articles /view/?site=testsite' 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) split uri=skylight2/articles/view/?site=testsite -> uri=skylight2/articles/view/, args=site=tes tsite 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] add per-dir prefix: skylight2/articles/view/ - > /home/stefano/webroot_aliases/testsite/skylight2/articles/view/ 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect /home/stefano/webroot_a liases/testsite/skylight2/articles/view/ [internal redirect] 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/w ebroot_aliases/testsite/home -> /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/testsite/skylight2/articles/view/ 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/we broot_aliases/testsite/home/stefano/webroot_aliases/testsite/skylight2/articles/view/ -> home/stefano/webroot_aliases/testsite/skylight2/articles/view/ 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$'  uri 'home/stefano/webroot_aliases/testsite/skylight2/articles/view/' 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'home/stefano/webroot_aliases/ testsite/skylight2/articles/view/' -> 'skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view//?site=testsite' 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) split uri=skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view//?sit e=testsite -> uri=skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view//, args=site=testsite&site=testsite 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add per-dir prefix: skylight2/home/ste fano/webroot_aliases/testsite/skylight2/articles/view// -> /home/stefano/webroot_aliases/testsite/skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view// 127.0.0.1 - - [09/mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect /home/stefano/w ebroot_aliases/testsite/skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view// [internal redirect] 

and on in infinite loop.

why apache keep adding path info? neither l nor dpi flags work.

edit #2

following terrye's advice used config:

rewriteengine on rewritebase /testsite rewriterule ^(?!skylight2)(.*)$ /skylight2/$1?site=testsite [qsa,l] 

and got this:

127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/articles -> /home/stefano/webroot_aliases/testsite/articles/view 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/articles/view -> articles/view 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' uri 'articles/view' 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'articles/view' -> '/skylight2/articles/view?site=testsite' 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (3) split uri=/skylight2/articles/view?site=testsite -> uri=/skylight2/articles/view, args=site=testsite 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] trying replace prefix /home/stefano/webroot_aliases/testsite/ /testsite 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect /skylight2/articles/view [internal redirect] 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a9968/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/skylight2 -> /home/stefano/webroot_aliases/testsite/skylight2/articles/view 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a9968/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/skylight2/articles/view -> skylight2/articles/view 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a9968/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' uri 'skylight2/articles/view' 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a9968/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] pass through /home/stefano/webroot_aliases/testsite/skylight2 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/favicon.ico -> favicon.ico 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' uri 'favicon.ico' 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'favicon.ico' -> '/skylight2/favicon.ico?site=testsite' 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (3) split uri=/skylight2/favicon.ico?site=testsite -> uri=/skylight2/favicon.ico, args=site=testsite 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] trying replace prefix /home/stefano/webroot_aliases/testsite/ /testsite 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect /skylight2/favicon.ico [internal redirect] 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a96f0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/skylight2 -> /home/stefano/webroot_aliases/testsite/skylight2/favicon.ico 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a96f0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/skylight2/favicon.ico -> skylight2/favicon.ico 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a96f0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' uri 'skylight2/favicon.ico' 127.0.0.1 - - [10/mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a96f0/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] pass through /home/stefano/webroot_aliases/testsite/skylight2 

apache throws "file not exist: /home/stefano/webroot_aliases/testsite/skylight2" error. correct url should instead /home/stefano/webroot_aliases/skylight2/articles/view.

could because virtualdocumentroot set testsite , can't out of once it's set?

by way, i'm using apache 2.2.22.

edit #3

i solved placing symlink "skylight2" in testsite, pointing "../skylight2". help!!

i've come across bug before , there old bugrep on fizzled out. can occur if fall-through on per directory context. since rewrite engine loops on htaccess files anyway, [l] doesn't mean last means "restart loop".

next rewrite rule wrong since document root home/stefano/webroot_aliases , rule targets in uri space not file space target should skylight2/$1/?site=testsite.

next negative lookahead assertion should not inside (.*) loop, try:

rewriterule ^(?!skylight2)(.*)$ skylight2/$1/?site=testsite [qsa,l] 

if doesn't work, append new rewrite.log extract. thanks.

update following comments

the rewrite log shows docroot of /home/stefano/webroot_aliases/testsite , redirects

articles/view -> testsite/skylight2/articles/view/?site=testsite 

which fails negative lookahead , loops again, case when do need leading / on replacement string:

rewritebase  /testsite rewriterule ^(?!skylight2)(.*)$ /skylight2/$1/?site=testsite [qsa,l] 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -