html、php、Javascriptなど

html、php、Javascriptなどメモのためのブログ。
適当に見つけて忘れないように書留めます。

.htaccessでのPCと携帯サイト振り分け方法

2007年12月13日 | cgi
.htaccessに、下記のように記述します。
全キャリア共通の携帯ページにアクセスさせる場合↓


RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^(DoCoMo|KDDI|DDIPOKET|UP.Browser|J-PHONE|Vodafone|SoftBank)
RewriteRule ^$ /mobile/ [R]


後は保存したときにhtaccess.txtなどで保存して、FTPでアップした後に.htaccessに書き換えるだけ。
すべてのキャリアでいけるはずです。
上記の場合のディレクトリ構造は

┌─
├mobile[携帯用ディレクトリ]
│└index.html[携帯用トップページ]
├.htaccess[作成したファイル]
│index.html[PC用ページ]
└─

のような構成の場合です。mobileの部分を各自の携帯用ディレクトリに入れて使ってください。

↓各キャリアごとの場合

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} DoCoMo
RewriteRule ^$ http://example.jp/i/index.html [R]

RewriteCond %{HTTP_USER_AGENT} J-PHONE
RewriteRule ^$ http://example.jp/j/index.html [R]

RewriteCond %{HTTP_USER_AGENT} UP.Browser
RewriteRule ^$ http://example.jp/au/index.html [R]
<参照サイト>
・http://blog.n-two.jp/?eid=626802
・http://document.secure.jp/tools/htaccess/htaccess.php
・http://nakamura.noblog.net/blog/d/10133088.html
・http://d.hatena.ne.jp/ALMIC/20060727
・http://developers.softbankmobile.co.jp/dp/tool_dl/web/useragent.php

1 コメント

コメント日が  古い順  |   新しい順
お世話になりました。 (コーヒー貴族)
2012-06-01 16:55:11
助かりました。ありがとうございました。
返信する