httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Igor Cicimov <icici...@gmail.com>
Subject Re: [users@httpd] Redirect to other server if file/directory does not exists.
Date Tue, 05 Aug 2014 08:36:35 GMT
On 05/08/2014 5:30 PM, "Ivan Bondarev" <ivan.bondarev@neklo.com> wrote:
>
> Hi.
>
> I have a similar issue.
>
> I need to make a rewrite rule for this URL:
>
> /geturl?url=http://example.com/somepicture.jpg
>
> to proxy it to the "url" parameter value.
>
> So, i used rules like this:
>
> RewriteEngine on
> RewriteOptions Inherit
> RewriteCond %{REQUEST_FILENAME}       !-f
> RewriteRule  ^/geturl?url=(.*)$                   $1         [P,L]
>
Is this inside  virtual host? First:

REQUEST_FILENAME
The full local filesystem path to the file or script matching the request,
if this has already been determined by the server at the time
REQUEST_FILENAME is referenced. Otherwise, such as when used in virtual
host context, the same value as REQUEST_URI.

So inside virtual host you need to give the absolute path to the file like:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f

Second mod_rewrite DOES NOT match against the query string (i cant remember
how many times i have said that on this list) so anything after and
including ? in the uri given to mod_rewrite like this:

RewriteRule  ^/geturl?url=(.*)$

will not work. You have to use RewriteCond with QUERY_STRING parameter,
like this:

RewriteCond %{QUERY_STRING} ^url=(.*)$

So, your final code would look something like this (not tested typing while
on the train):

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule  ^/geturl$    %1   [P,L]

> But if there is no such file "geturl", Apache responses with 404 error.
If this file is in there, then it responses 200 and do nothing :)
>
> I can't see any solution except writing a PHP-proxifying script.
>
> 05.08.2014 00:47, Mimiko пишет:
>>
>> Hello.
>>
>> I want to redirect/proxy all request to other server if file/directory
does not exists locally. In apache's help I've found this exmaple:
>>
>> RewriteCond %{REQUEST_URI}/$1 !-U
>> RewriteRule ^/(.*) http://otherserver/$1 [P,L]
>>
>> But it works if file/directory exists, and shows 404 file not found if
file does not exist. Why it does not proxy?
>>
>

Mime
View raw message