重定向到CI应用程序中的移动子域 [英] Redirecting to mobile subdomain in a CI application

查看:116
本文介绍了重定向到CI应用程序中的移动子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络应用程序,我想用jQuery Mobile创建一个移动版本。现有的应用程序内置在CodeIgniter;我将使用相同的控制器,模型在哪里可以; (特别是模型,因为我将需要相同的数据,无论如何,可能需要写新的控制器)。



我对如何开始感到有点困惑。我想把我的移动版本在子域( m.myhost.tld ),但是..因为我的应用程序在 www.myhost.tld



我知道我的意思是,可以使用CodeIgniter中的User Agent库来检测移动浏览器并相应地加载视图;我只是不知道如何让这个工作与一个子域。我需要在这里自定义我的 app / config / routes.php 文件,或者我可以用一些 .htaccess 魔术?我已经没有经验与 .htaccess 虽然。我唯一知道的是如何从CI应用程序中删除我的index.php,这是一个copypasta片段。



编辑:我想知道我可以使用一个教程,如< a href =http://net.tutsplus.com/tutorials/php/basecamp-style-subdomains-with-codeigniter/ =nofollow>这一个做我想做什么?它似乎在做或多或少相同的事情,只是与动态用户名,而不是一个简单的m。



编辑2:一些更多的信息,我猜。 / p>

说我使用CodeIgniter包含的用户代理库来检测移动浏览器。我想将这些浏览器导向 m.myhost.tld 。但是,我想在移动网站上显示的内容来自一个控制器 mobile ,我也可以通过 www.myhost.tld / mobile / ;所以我的问题是如果有一个方法来路由一个URL例如 www.myhost.tld / mobile / about m.myhost .tld / about 。我甚至不确定这是否可能,teehee。仍在学习!



我会感谢你能给我的任何建议。非常感谢!

解决方案

如果您想在不同主机中共享相同的文件,



浏览器 - > host:zyxxx [ip.ip.ip]这是静态文件的解释, .ip] - > web server - > read filesystem:document root + browser request path



所以如果你的文档根目录是:

  / hosting / http / zyxxx / htdocs 

,请求是/path-to-static/index.html服务器尝试读取:

  / hosting / http /zyxxx/htdocs/path-to-static/index.html 

在此之前,您创建新主机m.mysite.tld在您的Web服务器中,并更改文档根目录与www.mysite.tld相同,您还可以使用主机别名的指令,如Apache ServerAlias指令。



您可以使用 $ _ SERVER ['HTTP_HOST']处理php中的主机名称



如果您可以指定更多,我可以帮助更多。

有一个愉快的一天


I have a web app of which I would like to create a mobile version with jQuery Mobile. The existing application is built in CodeIgniter; I'll be using the same controllers, models where I can; (especially models since I'll be needing the same data anyway, might have to write new controllers).

I'm a bit confused as to how to get started. I want to put my mobile version on a subdomain (m.myhost.tld), however.. since my app is at www.myhost.tld and I don't feel like copying it all over to another folder and maintain two, I'm a bit confused.

I know I can use the User Agent library in CodeIgniter to detect mobile browsers and load views accordingly; I just don't know how to get this working with a subdomain. Do I need to customize my app/config/routes.php file here, or can I fix this with some .htaccess magic? I have next to none experience with .htaccess though. The only thing I know is how to remove my index.php from CI apps, and that's a copypasta snippet.

EDIT: I wonder if I can use a tutorial like this one to do what I want to do? It seems to be doing more or less the same thing, just with dynamic usernames instead of a simple 'm.'

EDIT 2: Some more information, I guess.

Say I detect mobile browsers using the User Agent library included with CodeIgniter. I want to direct these browsers to m.myhost.tld. However, the content that I want to display on the mobile website comes from a controller called mobile which I can also access through www.myhost.tld/mobile/; so my question is if there is a way to route a URL like.. for example www.myhost.tld/mobile/about to m.myhost.tld/about. I'm not even sure if this is possible, teehee. Still learning!

I'll be grateful for any advice you can give me. Thanks a lot!

解决方案

If you want to share the same files in different hosts, you must assign the document root folder of your sites in your web server, this is an explanation for static files, but is the base to you understand.

browser -> host:z.y.xxx[ip.ip.ip.ip] -> web server -> read filesystem : document root + browser request path

so if your document root is:

/hosting/http/z.y.xxx/htdocs

and the request is /path-to-static/index.html the server try to read:

/hosting/http/z.y.xxx/htdocs/path-to-static/index.html

In conclution, you create the new host m.mysite.tld in your web server and you change the document root as the same of the you www.mysite.tld also you could use directives of host alias, like Apache ServerAlias directive. Have lot of documentation to how you could configure a web server.

You could handle the host name in php with $_SERVER['HTTP_HOST'] variable.

If you could specify more, I could help more.

have a nice day

这篇关于重定向到CI应用程序中的移动子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆