mod rewrite - Apache mod_rewrite catch all (.*) does not work as intended -
following excerpt of httpd.conf. want catch unmatched requests @ [2] , reverse proxy http://localhost:8585. however, links sent http://localhost:8585/var/ww/html/
documentroot "/var/www/html"  <directory />     options followsymlinks     allowoverride none     rewriteengine on     rewriterule testing/(.*) http://localhost:8585/mytesting/$1 [p,l] # [1]     rewriterule (.*) http://localhost:8585/$1 [p,l] # [2] catch rule  </directory> here test tried , result after rewrite
good result
http://localhost/testing/ => http://localhost:8585/mytesting/ [3] http://localhost/testing/goodone => http://localhost:8585/mytesting/goodone [4]
bad result
http://localhost:8080/testing => http://localhost:8585/var/www/html/testing [5]  expect http://localhost:8585/testing
http://localhost:8080/ => http://localhost:8585/var/www/html/ [6]   expect http://localhost:8585/
the problem obvious last rewriterule prepended documentroot(/var/www/html/) after rewrite. did wrong? or intended behavior? , how can fix/workaround have expected result?
output rewritelog , rewriteloglevel 2
[3]
::1 - - [{date}] [xxx][yyy] (2) [perdir /] rewrite 'var/www/html/testing/' -> 'http://localhost:8585/mytesting/' ::1 - - [{date}] [xxx][yyy] (2) [perdir /] escaped uri in per-dir context proxy, http://localhost:8585/mytesting/ -> http://localhost:8585/mytesting/ ::1 - - [{date}] [xxx][yyy] (2) [perdir /] forcing proxy-throughput http://localhost:8585/mytesting/ ::1 - - [{date}] [xxx][yyy] (1) [perdir /] go-ahead proxy request proxy:http://localhost:8585/mytesting/ [ok] [4]
::1 - - [{date}] [xxx][yyy] (2) [perdir /] rewrite 'var/www/html/testing/goodone' -> 'http://localhost:8585/mytesting/goodone' ::1 - - [{date}] [xxx][yyy] (2) [perdir /] escaped uri in per-dir context proxy, http://localhost:8585/mytesting/goodone -> http://localhost:8585/mytesting/goodone ::1 - - [{date}] [xxx][yyy] (2) [perdir /] forcing proxy-throughput http://localhost:8585/mytesting/goodone ::1 - - [{date}] [xxx][yyy] (1) [perdir /] go-ahead proxy request proxy:http://localhost:8585/mytesting/goodone [ok] [5]
::1 - - [{date}] [xxx][yyy] (2) [perdir /] rewrite 'var/www/html/testing' -> 'http://localhost:8585/var/www/html/testing' ::1 - - [{date}] [xxx][yyy] (2) [perdir /] escaped uri in per-dir context proxy, http://localhost:8585/var/www/html/testing -> http://localhost:8585/var/www/html/testing ::1 - - [{date}] [xxx][yyy] (2) [perdir /] forcing proxy-throughput http://localhost:8585/var/www/html/testing ::1 - - [{date}] [xxx][yyy] (1) [perdir /] go-ahead proxy request proxy:http://localhost:8585/var/www/html/testing [ok] [6]
::1 - - [{date}] [xxx][yyy] (2) [perdir /] rewrite 'var/www/html/' -> 'http://localhost:8585/var/www/html/' ::1 - - [{date}] [xxx][yyy] (2) [perdir /] escaped uri in per-dir context proxy, http://localhost:8585/var/www/html/ -> http://localhost:8585/var/www/html/ ::1 - - [{date}] [xxx][yyy] (2) [perdir /] forcing proxy-throughput http://localhost:8585/var/www/html/ ::1 - - [{date}] [xxx][yyy] (1) [perdir /] go-ahead proxy request proxy:http://localhost:8585/var/www/html/ [ok] 
your regular expression requires "/" after "testing", if optional second example implies, update regexp reflect this, adding ?, it's practise use %{request_uri} rather unnecessary (.*) + $1 combo eg.
rewriterule testing/?(.*) http://localhost:8585/mytesting/$1 [p,l] rewriterule .* http://localhost:8585%{request_uri} [p,l]  
Comments
Post a Comment