接続元によってWebページのリダイレクト先を変える方法です。
リダイレクトを JavaScript で行います。
以下の行を実行すると、リダイレクトされます。
<script type="text/javascript">location.href = "リダイレクト先URL";</script>
cgiで下記のようにすると、接続元IPアドレスによって、リダイレクト先を変更できます。
#!/usr/bin/perl
my $ip = $ENV{'REMOTE_ADDR'};
print "Content-type:text/html\n\n";
if( $ip =~ /192\.168\.0\.\d/ ){
print redirect('http://www.google.co.jp');
}else{
print redirect('http://www.yahoo.co.jp' );
}
sub redirect {
return "<script type=\"text/javascript\">location.href = \"$_[0]\";</script>";
}
コメント