 |
วิธีเขียนเว็บให้แสดงผลสำหรับเว็บบนมือถือ แบบเว็บ mthai.com แบบ redirect ไปที่ sub domain ของ mobile |
|
 |
|
|
 |
 |
|
ถ้าเดานะ น่าจะมีตัวเช็ค ว่าใช้อินเตอร์เน็ตจากช่องทางไหน
เช่น เบราเซอร์ Firefox หรือ เบราเซอร์มือถือ เช่น Opera
ระบบก็จะทำการ Redirect ไปยัง url ที่ต้องการ น่าจะประมาณนั้น
|
 |
 |
 |
 |
Date :
2012-04-24 17:50:10 |
By :
asustak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
นั่นนะซิครับ ไม่ทราบว่าจะพอมีตัวอย่างมั๊ยครับ
สมมุติผมทำเว็บแยกออกเป็น 2 เวอร์ฃั่น คือเว็บหลัก และเว็บเวอร์ชั่นมือถือ
โดยที่เว็บหลักมีโดเมน คือ http://www.test.com
และเว็บสำหรับมือถือมีซับโดเมน คือ http://m.test.com
และถ้าผู้ใช้เข้าเว็บผม โดยใช้มือถือ ipone หรือ android เข้ารับชม
แม้ว่าผู้ใช้จะพิมพ์ url เป็น http://www.test.com แต่มันก็จะ redirect url มาที่ http://m.test.com
ไม่ทราบจะมีวิธี check หรือเขียนได้ยังไงร๋อครับ
ปล.ถ้าไงรบกวนด้วยนะครับ ถ้ามีตัวอย่างจะขอขอบคุณมากๆเลยอ่าครับ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2012-04-24 20:32:02 |
By :
auncore |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ $_SERVER['HTTP_USER_AGENT'] ครับ ตรวจสอบ Web Browser
Code (PHP)
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/iPhone|Android|Blackberry/i', $agent)){
header("location:http://m.thaicreate.com");
exit;
}
?>
|
 |
 |
 |
 |
Date :
2012-04-24 20:41:37 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อีกตัว
Code
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# prevent looping
RewriteCond %{HTTP_HOST} !^m.mysite.com$
# if the browser accepts these mime-types, it's definitely mobile, or pretending to be
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
# a bunch of user agent tests
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]
# rewrite rules here
RewriteRule ^(.+)\$ http://m.mysite.com/$1 [R=302,NC]
|
 |
 |
 |
 |
Date :
2012-06-14 09:29:11 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|