LPO検索→
結局ユーザーエージェントを判別してページを振り分ける方法は、以下のサイトでのスクリプトを参考にして作ることにした。CGIを使ってのページ振り分けが妥当と判断。
ブラウザ判別とプラットフォームの判別をうまく使って振り分ける
willcom のブラウザ環境のユーザーエージェントの規定をみると、プラットフォームがwindows CEというの判別できればいいか。
if ( $UserAgent =~ /(Windows |Win)(CE)/ )
- Japan.internet.com コラム/千客万来!Web への扉
- http://japan.internet.com/column/webtech/20040929/8.html
CGI または PHP を利用して、User-Agent 情報に含まれる"DoCoMo"、"UP.Browser"、"J-Phone"といった文字列を判別し、それぞれリダイレクト先を指定。また、携帯電話を示す文字列が User-Agent に含まれない場合は PC からアクセスされたものとして、PC 用のコンテンツにリダイレクトするようにします。
・CGI の記述
#!/usr/bin/perl -w $agent = $ENV{’HTTP_USER_AGENT’}; if($agent =~ /DoCoMo/){ print "Location: http://example.jp/i/index.html"; exit; } elsif($agent =~ /UP.Browser/){ print "Location: http://example.jp/e/index.html"; exit; } elsif($agent =~ /J-PHONE/){ print "Location: http://example.jp/v/index.html"; exit; } else{ print "Location: http://example.jp/home.html"; exit; }
・PHP の記述
<? $header = getallheaders(); $agent = $header["User-Agent"] ; if(ereg("DoCoMo",$agent)){ header("Location: http://example.jp/i/index.html"); exit; } elseif(ereg("UP.Browser",$agent)){ header("Location: http://example.jp/e/index.html"); exit; } elseif(ereg("J-PHONE",$agent)){ header("Location: http://example.jp/v/index.html"); exit; } else{ header("Location: http://example.jp/home.html"); exit; } ?>
あとは、.htaccessの設定をしてまずCGIのページへのリダイレクトをすることに。
DirectoryIndex index.cgi index.html
- index.cgiやindex.phpをトップページにする方法
- http://www.shtml.jp/htaccess/directoryindex.html

コメントする