Hi Perrin,
I'm just not aware yet that I could check the outcome of a subrequest and
put some proxied response in place if the subrequest is unsuccessful. Isn't
mod-rewrite just a _request_ rewrite ?
It can do just about anything:
http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
Looks like it should be simple. And still I can't get it do what I want.
There is actually an almost _exact_ FAQ-like answer to my problem in the
doc, http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide_advanced.html:
---
Redirect Failing URLs to Another Web Server
Description:
A typical FAQ about URL rewriting is how to redirect failing requests
on webserver A to webserver B. Usually this is done via ErrorDocument CGI
scripts in Perl, but there is also a mod_rewrite solution. But note that
this performs more poorly than using an ErrorDocument CGI script!
Solution:
The first solution has the best performance but less flexibility, and
is less safe:
RewriteEngine on
RewriteCond /your/docroot/%{REQUEST_FILENAME} !-f
RewriteRule ^(.+) http://webserverB.dom/$1
The problem here is that this will only work for pages inside the
DocumentRoot. While you can add more Conditions (for instance to also
handle homedirs, etc.) there is a better variant:
RewriteEngine on
RewriteCond %{REQUEST_URI} !-U
RewriteRule ^(.+) http://webserverB.dom/$1
This uses the URL look-ahead feature of mod_rewrite. The result is
that this will work for all types of URLs and is safe. But it does have a
performance impact on the web server, because for every request there is
one more internal subrequest. So, if your web server runs on a powerful
CPU, use this one. If it is a slow machine, use the first approach or
better an ErrorDocument CGI script.
---
So it seems to be very, very easy. Still, when using the above receipt
like
RewriteEngine on
RewriteCond %{REQUEST_URI} !-U
RewriteRule ^\/(.+) http://OLDDOMAIN.COM/$1 [QSA,P]
instead of getting the proxied content, I get
---
Not Found
The requested URL /index.php was not found on this server.
---
for a GET request like http://mydomain.com/index.php and the rewrite log
(with RewriteLogLevel 9) looks like
[rid#2ad8dc3dfb98/initial] (2) init rewrite engine with requested uri /index.php
[rid#2ad8dc3dfb98/initial] (3) applying pattern '^\/(.+)' to uri '/index.php'
[rid#2ad8dc3e5bc8/subreq] (2) init rewrite engine with requested uri /index.php
[rid#2ad8dc3e5bc8/subreq] (3) applying pattern '^\/(.+)' to uri '/index.php'
[rid#2ad8dc3e5bc8/subreq] (4) RewriteCond: input='/index.php' pattern='!-U' =>
matched
[rid#2ad8dc3e5bc8/subreq] (2) rewrite '/index.php' ->
'http://OLDDOMAIN.COM/index.php'
[rid#2ad8dc3e5bc8/subreq] (2) forcing proxy-throughput with
http://OLDDOMAIN.COM/index.php
[rid#2ad8dc3e5bc8/subreq] (1) go-ahead with proxy request
proxy:http://OLDDOMAIN.COM/index.php [OK]
[rid#2ad8dc3dfb98/initial] (5) RewriteCond URI (-U) check: path=/index.php ->
status=200
[rid#2ad8dc3dfb98/initial] (4) RewriteCond: input='/index.php' pattern='!-U' =>
not-matched
[rid#2ad8dc3dfb98/initial] (1) pass through /index.php
If I do the proxying unconditionally, like
RewriteEngine on
# RewriteCond %{REQUEST_URI} !-U
RewriteRule ^\/(.+) http://OLDDOMAIN.COM/$1 [QSA,P]
it works OK.
Any clou/idea of what might be wrong here ?
Many thanks,
Iosif Fettich