OMG, it worked as tiny swiss clocks! Thanks Igor.
05.08.2014 12:36, Igor Cicimov пишет:
On 05/08/2014 5:30 PM, "Ivan Bondarev" <ivan.bonda...@neklo.com
<mailto:ivan.bonda...@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:
No, this is not a virtual host. But thanks for advice.
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=(.*)$
I don't know how i missed this topic in documentation, but i didn't mind
this. Looks like this is really actual topic if two guys asks the
question which is already answered for a thousand times.
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]
Worked like a charm!
> 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?
>>
>