I have special parameter data=/path/to/filename.htm
in uri.
Its old and rusty site builded on SSI, and I can't modify it.
Problem is when filename passed as arg_data not exists, page is broken.
I want redirect to 404.htm in this case.
Something like that:
if (!-f $arg_data){
rewrite ^.*$ /404.htm last;
}
But I get:
rewrite or internal redirection cycle while processing "/404.htm
I think its because I didn't check if arg_data
exists.
But nginx have not nested if-s.
I tried:
set $data index.htm;
if ($args ~ "data=(.+)") {
set $data $1;
}
if (!-f $data) {
rewrite ^.*$ /404.htm last;
}
Idea was set $data
to some file which 100% exists, and after that rewrite if data param is passed.
For some reason its give the same error, internal redirection cycle
Looks like I do it in wrong way.
OK, this is a very strange scenario, and you seem to be on the right track.
Instead of the
rewrite
, though, I wouldreturn 404;
and use anerror_page
to define the 404 error page.For example:
Ok, so regarding the last comments we had, you need an
AND
condition for twoif
statements.NGinx
is not able to do this.To achieve this, we will use a little trick dealing with a
$test
var :