Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache ErrorDocument External Redirect with Variables

Is something like this possible in Apache ... (i.e. redirect to an external url with the path causing the 403 error passed along)

ErrorDocument 403 http://www.sample.com/{{REDIRECT_URL}}
like image 207
Pykler Avatar asked Jun 07 '12 20:06

Pykler


1 Answers

ErrorDocument configuration option, unfortunatelly, doesn't support server variables expansion. What you can try is to use local script, that will issue redirect for you.

ErrorDocument 403 /cgi-bin/error.cgi

Note, that script has to be local, otherwise you won't get REDIRECT_* variables passed. And in the script itself you can issue redirect statement:

#!/usr/bin/perl
my $redirect_status = $ENV{'REDIRECT_STATUS'} || '';
my $redirect_url = $ENV{'REDIRECT_URL'} || '';

if($redirect_status == 403) {
    printf("Location: http://%s%s\n", 'www.sample.com', $redirect_url);
    printf("Status: %d\n", 302);
}
print "\n";

See Apache documentation for more insights http://httpd.apache.org/docs/2.4/custom-error.html

like image 177
Timur Bakeyev Avatar answered Sep 19 '22 15:09

Timur Bakeyev