什么是最新和正确的移动重定向方法

时间:2015-03-12 04:14:46

标签: php performance redirect mobile

目前我正在开展一些酒店项目,在考虑响应式设计之前,但很难并且不符合客户的需求。是否有某种移动重定向方法可以完美运行..

2 个答案:

答案 0 :(得分:0)

如果您的项目基于PHP,那么我建议使用Mobile Detect。一个例子:

<?php

require_once 'Mobile_Detect.php';

$detect = new MObile_Detect;

if($detect->isMobile())
{
    // ... create mobile view or PHP header
}

值得注意的是,您可以选择设备是iOS,Android还是平板电脑。

答案 1 :(得分:-1)

其实我用Javascript得到答案谢谢大家。 此代码应位于索引页

 (function(){

var userAgent = navigator.userAgent || navigator.vendor || window.opera;    var mobile =(/(android | bb \ d+ |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| maemo | midp | mmp | mobile。+ firefox | netfront | opera m(ob | in)i | palm(os)?| phone | p(ixi | re)/ | plucker | pocket | psp | series(4 | 6) 0 | symbian | treo | up。(浏览器|链接)| vodafone | wap | windows ce | xda | xiino / i.test(userAgent)|| / 1207 | 6310 | 6590 | 3gso | 4thp | 50 [1-6] i | 770s | 802s | a wa | abac | ac(er | oo | s - )| ai(ko | rn)| al(av | ca | co)| amoi | an(ex | ny | yw)| aptu | ar(ch | go)| as(te | us)| attw | au(di | -m | r | s)| avan | be(ck | ll | nq)| bi(lb | rd)| bl(ac | AZ)| BR(E | v)的W | bumb | BW-(N | U)| C55 / | CAPI | CCWA | CDM-|细胞| CHTM | CLDC | CMD- |ω(MP | ND)|嗉|哒(它| LL | NG)| dbte | DC-S |德维| DICA | dmob |做(C | p)的直径:| DS(12 | -d)| EL(49 | AI)| EM(L2 | UL)|呃(ic | k0)| esl8 | ez([4-7] 0 | os | wa | ze)| fetc | fly( - | )| g1 u | g560 | gene | gf-5 | g-mo | go(.w | od)| gr(ad | un)| haie | hcit | hd-(m | p | t)| hei- | hi(pt | ta)| hp(i | ip)| hs-c | ht(c( - | | | a | g | p | s | t)| tp)| hu(aw | tc)| i-(20 | go | ma)| i230 | iac(| - | /)| ibro | idea | ig01 | ikom | im1k | inno | ipaq | iris | ja(t | v)a | jbro | jemu | jigs | kddi | keji | kgt(| /)| klon | kpt | kwc- | kyo(c | k)| le(no | xi)| lg(g | /(k | l | u)| 50 | 54 | - [aw])| libw | lynx | m1-w | m3ga | M50 / | MA(TE | UI | XO)| MC(01 | 21 | CA)| M-CR |我(RC | RI)|英里(O8 | OA | TS)| MMEF |莫(01 | 02 | BI |代|做| T( - | | o | v)| zz)| mt(50 | p1 | v)| mwbp | mywa | n10 [0-2] | n20 [2-3] | n30(0 | 2)| n50(0 | 2 | 5 )| N7(0(0 | 1)| 10)| NE((C | M) - |在| TF | WF | WG |重量)| NOK(6 | I)| nzph | o2im | OP(TI | WV )|奥兰| owg1 | P800 |锅(A | d | T)| pdxg | PG(13 | - ([1-8] | C))|菲尔| PIRE | PL(AY | UC)| PN-2 |婆(CK |室温| SE)| PROX | PSIO | PT-G | QA-A | QC(07 | 12 | 21 | 32 | 60 | - [2-7] |异)| QTEK | R380 | R600 | RAKS | rim9 | RO(VE | ZO)| S55 / | SA(GE |毫安|毫米|毫秒| NY | VA)| SC(01 | H- | oo的|对 - )| SDK / | SE(C( - | 0 | 1)| 47 | MC | ND | RI)| SGH- |沙皮| SIE( - | M)| SK-0 | SL(45 | ID)| SM(AL | AR | B3 |它| T5) | so(ft | ny)| sp(01 | h- | v- | v)| sy(01 | mb)| t2(18 | 50)| t6(00 | 10 | 18)| ta(gt | lk) | tcl- | tdg- |电话(I | M)|做为计时| T型钼|至(PL | SH)| TS(70 |间 - |立方米| M5)| TX-9 |向上(.B | G1 | SI)| utst | V400 | V750 | VERI | VI(RG | TE)| VK(40 | 5 [0-3] | -v)| vm40 |沃达| vulc | VX(52 | 53 | 60 | 61 | 70 | 80 | 81 | 83 | 85 | 98)| w3c( - |)| webc | whit | wi(g | nc | nw)| wmlb | wonu | x700 | yas- | your | zeto | zte- / i。试验(userAgent.substr(0,4)));

//您的移动和桌面网址    var mobileURL ='http://m.myweb.com/';

if(mobile)window.location = mobileURL + window.location.search + window.location.hash;    else window.location = desktopURL + window.location.search + window.location.hash;

})();

此代码应位于移动索引页

 (function(){

var userAgent = navigator.userAgent || navigator.vendor || window.opera;    var mobile =(/(android | bb \ d+ |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| maemo | midp | mmp | mobile。+ firefox | netfront | opera m(ob | in)i | palm(os)?| phone | p(ixi | re)/ | plucker | pocket | psp | series(4 | 6) 0 | symbian | treo | up。(浏览器|链接)| vodafone | wap | windows ce | xda | xiino / i.test(userAgent)|| / 1207 | 6310 | 6590 | 3gso | 4thp | 50 [1-6] i | 770s | 802s | a wa | abac | ac(er | oo | s - )| ai(ko | rn)| al(av | ca | co)| amoi | an(ex | ny | yw)| aptu | ar(ch | go)| as(te | us)| attw | au(di | -m | r | s)| avan | be(ck | ll | nq)| bi(lb | rd)| bl(ac | AZ)| BR(E | v)的W | bumb | BW-(N | U)| C55 / | CAPI | CCWA | CDM-|细胞| CHTM | CLDC | CMD- |ω(MP | ND)|嗉|哒(它| LL | NG)| dbte | DC-S |德维| DICA | dmob |做(C | p)的直径:| DS(12 | -d)| EL(49 | AI)| EM(L2 | UL)|呃(ic | k0)| esl8 | ez([4-7] 0 | os | wa | ze)| fetc | fly( - | )| g1 u | g560 | gene | gf-5 | g-mo | go(.w | od)| gr(ad | un)| haie | hcit | hd-(m | p | t)| hei- | hi(pt | ta)| hp(i | ip)| hs-c | ht(c( - | | | a | g | p | s | t)| tp)| hu(aw | tc)| i-(20 | go | ma)| i230 | iac(| - | /)| ibro | idea | ig01 | ikom | im1k | inno | ipaq | iris | ja(t | v)a | jbro | jemu | jigs | kddi | keji | kgt(| /)| klon | kpt | kwc- | kyo(c | k)| le(no | xi)| lg(g | /(k | l | u)| 50 | 54 | - [aw])| libw | lynx | m1-w | m3ga | M50 / | MA(TE | UI | XO)| MC(01 | 21 | CA)| M-CR |我(RC | RI)|英里(O8 | OA | TS)| MMEF |莫(01 | 02 | BI |代|做| T( - | | o | v)| zz)| mt(50 | p1 | v)| mwbp | mywa | n10 [0-2] | n20 [2-3] | n30(0 | 2)| n50(0 | 2 | 5 )| N7(0(0 | 1)| 10)| NE((C | M) - |在| TF | WF | WG |重量)| NOK(6 | I)| nzph | o2im | OP(TI | WV )|奥兰| owg1 | P800 |锅(A | d | T)| pdxg | PG(13 | - ([1-8] | C))|菲尔| PIRE | PL(AY | UC)| PN-2 |婆(CK |室温| SE)| PROX | PSIO | PT-G | QA-A | QC(07 | 12 | 21 | 32 | 60 | - [2-7] |异)| QTEK | R380 | R600 | RAKS | rim9 | RO(VE | ZO)| S55 / | SA(GE |毫安|毫米|毫秒| NY | VA)| SC(01 | H- | oo的|对 - )| SDK / | SE(C( - | 0 | 1)| 47 | MC | ND | RI)| SGH- |沙皮| SIE( - | M)| SK-0 | SL(45 | ID)| SM(AL | AR | B3 |它| T5) | so(ft | ny)| sp(01 | h- | v- | v)| sy(01 | mb)| t2(18 | 50)| t6(00 | 10 | 18)| ta(gt | lk) | tcl- | tdg- |电话(I | M)|做为计时| T型钼|至(PL | SH)| TS(70 |间 - |立方米| M5)| TX-9 |向上(.B | G1 | SI)| utst | V400 | V750 | VERI | VI(RG | TE)| VK(40 | 5 [0-3] | -v)| vm40 |沃达| vulc | VX(52 | 53 | 60 | 61 | 70 | 80 | 81 | 83 | 85 | 98)| w3c( - |)| webc | whit | wi(g | nc | nw)| wmlb | wonu | x700 | yas- | your | zeto | zte- / i。试验(userAgent.substr(0,4)));

//您的移动和桌面网址    var mobileURL ='http://myweb.com/';

if(mobile)window.location = mobileURL + window.location.search + window.location.hash;    else window.location = desktopURL + window.location.search + window.location.hash;

})();