htaccess でキャリア振り分け
使い道
厳密ではなく簡易的に、かつ簡単に実装したい場合。
記述例(1)
まとめて記述
#RewriteEngineを有効にする RewriteEngine on #↓ユーザエージェントからを見てそれぞれのページへ #携帯 RewriteCond %{HTTP_USER_AGENT} ^DoCoMo [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^KDDI [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^Up.Browser [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^J-PHONE [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^vodafone [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^SoftBank [NC] RewriteRule ^.*$ http://*****.***/mobile/ [L] #アップル RewriteCond %{HTTP_USER_AGENT} ^iPod [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^iPad [NC,OR] RewriteCond %{HTTP_USER_AGENT} ^iPhone [NC] RewriteRule ^.*$ http://*****.***/iphone/ [L] #アンドロイド RewriteCond %{HTTP_USER_AGENT} ^Android [NC] RewriteRule ^.*$ http://*****.***/android/ [L]
記述例(2)
一つ一つ分けて記述
# Options -Indexes # < IfModule mod_rewrite.c> # DoCoMo RewriteEngine On RewriteCond %{HTTP_USER_AGENT} DoCoMo RewriteRule ^$ /smp/ [R] # Softbank RewriteCond %{HTTP_USER_AGENT} J-PHONE RewriteRule ^$ /smp/ [R] RewriteCond %{HTTP_USER_AGENT} Vodafone RewriteRule ^$ /smp/ [R] RewriteCond %{HTTP_USER_AGENT} SoftBank RewriteRule ^$ /smp/ [R] # AU KDDI RewriteCond %{HTTP_USER_AGENT} KDDI RewriteRule ^$ /smp/ [R] RewriteCond %{HTTP_USER_AGENT} UP.Browser RewriteRule ^$ /smp/ [R] # DDI Pocket RewriteCond %{HTTP_USER_AGENT} DDIPOCKET RewriteRule ^$ /smp/ [R] # WILLCOM RewriteCond %{HTTP_USER_AGENT} WILLCOM RewriteRule ^$ /smp/ [R] # iPod RewriteCond %{HTTP_USER_AGENT} iPod RewriteRule ^$ /smp/ [R] # iPhone RewriteCond %{HTTP_USER_AGENT} iPhone RewriteRule ^$ /smp/ [R] # Android RewriteCond %{HTTP_USER_AGENT} Android RewriteRule ^$ /smp/ [R] # WILLCOM RewriteCond %{HTTP_USER_AGENT} PDA RewriteRule ^$ /smp/ [R] # IE # RewriteEngine On # RewriteCond %{HTTP_USER_AGENT} MSIE # RewriteRule ^$ /msie/ [R] # PC Internet Explorer Firefox # RewriteCond %{HTTP_USER_AGENT} Mozilla # RewriteRule ^$ / [R] # PC Opera # RewriteCond %{HTTP_USER_AGENT} Opera # RewriteRule ^$ / [R] # Mac Safari # RewriteCond %{HTTP_USER_AGENT} Safari # RewriteRule ^$ / [R] # < /IfModule>