ysk331homme回答ポイント 70ptウォッチ

PCページと携帯ページのPHPによる振り分けについて質問です。

現在、PC用ページを ⇒ http://example.com/に設置し、
携帯用のページを  ⇒ http://example.com/mobi/に設置したいと思っています。
そこで、PC用の各ページの頭に、直接PHPスクリプトを書いて、
携帯だけ、飛ばしてしまう。という方法がやりたいのですが。
-------------------
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match("/^DoCoMo/i", $agent)){
header("Location: http://example.com/mobi/");
exit;
}else if(preg_match("/^(J-PHONE|Vodafone|MOT-[CV]|SoftBank)/i", $agent)){
header("Location: http://example.com/mobi/");
exit;
}else if(preg_match("/^KDDI-/i", $agent) || preg_match("/UP.Browser/i", $agent)){
header("Location: http://example.com/mobi/");
exit;
}else{
header("Location: http://example.com/index.html");
exit;
}
-------------------
こうすると、無限リダイレクトにおちいってしまいました。
要は、http://example.com/index.html にアクセスしたとき、
PCはそのままこのページを閲覧できる。
携帯のみ http://example.com/mobi/index.html に飛ばす。
ということがやりたいです。
PHPに強い方、宜しくお願いいたします。

※ 有料アンケート・ポイント付き質問機能は2023年2月28日に終了しました。
ログインして回答する

みんなの回答

この質問へのコメント

この質問への反応(ブックマークコメント)

質問の情報

登録日時
2010-12-16 18:55:52
終了日時
2010-12-16 20:53:40
回答条件
1人5回まで

この質問のカテゴリ

この質問に含まれるキーワード

J-PHONE49vodafone285PHP7798SoftBank424KDDI112スクリプト2307DoCoMo828CV18MOT14リダイレクト414EXIT194

人気の質問

メニュー

PC版