apache 404 跳转功能


<<httpd.conf>>

yum install mod_perl   # 安装 apache perl 模块
yum install perl-CGI #perl CGI模块
AddHandler cgi-script .cgi .sh .pl
httpd.conf 配置全局变量 :
SetEnv REDIRECT_DEST_PREFIX http://app.gateares.com:18080/gcenter-syncservice
日志显示 404 跳转 :
Alias /ipsimage "/u01/gcenter/images/"
<Directory "/u01/gcenter/images">
Options MultiViews
AllowOverride All
Order allow,deny
Allow from all
ErrorDocument 404 "/cgi-bin/find2.sh"
</Directory>
find2.sh:( 需要大于 512 字节 ,IE 才能识别跳转 .)
#!/bin/bash
echo  content - type :  text / html
echo   ""
REDIRECT_URL = `echo  $REDIRECT_URL | sed  s #/appimage#/ipsimage#`
cat   <<  EOM1
< html >
< meta http - equiv = "refresh"  content = "0;url=http://app.gateares.com:18080/gcenter-syncservice$REDIRECT_URL" >
<!--
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000
-->
</ html >
EOM1

日志显示 301 跳转 :
Alias /ipsimage "/u01/gcenter/images/"
<Directory "/u01/gcenter/images">
Options MultiViews
AllowOverride All
Order allow,deny
Allow from all
ErrorDocument 404 "/cgi-bin/redirect.pl"
</Directory>
redirect.pl:
#!/usr/bin/perl
use   strict ;
use   CGI;

my   $ q   = new CGI;
my $dest=$ENV{"REDIRECT_DEST_PREFIX"}.$ENV{"REDIRECT_URL"};
my $query_str = $ENV{"REDIRECT_QUERY_STRING"};
$dest .= "?".$query_str if(defined $query_str);
print $q->redirect($dest);