条件指定リダイレクト(Location)
#! /usr/local/bin/ruby arr = [ # 転送条件 # 特定ユーザーエージェント転送の場合 [ENV['HTTP_USER_AGENT'], "DoCoMo"], [ENV['HTTP_USER_AGENT'], "KDDI"], [ENV['HTTP_USER_AGENT'], "Softbank"], # 特定IPアドレス転送の場合 [ENV['REMOTE_ADDR'], "111.222.333.444"], # 特定リンク元転送の場合 [ENV['HTTP_REFERER'], "https://www.webings.net/"] ] arr.each { |k, v| if k =~ /#{v}/ print "Location: ../../sample/\n\n" # 転送 exit end } print "Content-type: text/html\n\n" print <<END <html> <head> <title>リダイレクト(条件指定)</title> </head> <body> ようこそ!!<br> </body> </html> END exit
〔 実行する 〕