Redirecting mobile devices without using a sub-domain
I'm interested in building a mobile site and have done some research on the subject. Everywhere I've looked contains information on either changing CSS upon detecting a mobile device, or setting up a sub-domain to redirect mobile browsers to.
My questions is: can I redirect mobile browsers to a different HTML page without having create a sub-domain? I'm thinking that it may be possible to do with a php page located alongside my HTML, CSS, etc. but I don't know that much a开发者_JAVA百科bout PHP (I'm currently learning the language now).
Redirecting to a subdomain is only used to keep everything organized.
It's easier to keep everything separate if you have a separate view running. It will be the same site, just that the view it is serving is mobile friendly. So you could have site.com/page
as your normal site, and site.com/page_mobile
as you mobile if you wanted, but this isn't recommended.
Much better to have a subdomain/site or at least a separate folder site.com/mobile/page
. This pattern will just give you a lot of flexibility when working with multiple sites
You can use $_SERVER['HTTP_USER_AGENT'] value of php to detect if request coming from a mobile browser. Then you can redirect user to a simple www.yoursite.com/mobile.php file by php header function.
Your question has solutions on Auto detect mobile browser (via user-agent?) question.
精彩评论