Codeigniter,域名到网站的某个区域

发布于 2024-09-26 03:29:31 字数 943 浏览 0 评论 0原文

我不是一个非常有经验的程序员,这是第二次使用 CodeIgniter。

假设我有 www.domain1.com。所以我会有 3 个控制器 /area1、/area2、/area3。如果我将基本 URL 设置为 www.domain1.com,用户可以通过 www.domain1.com/area1 等访问它们。但我的问题是,客户想要网络的某个区域,比如area2,在自己的域中作为微型网站工作,所以他想通过www.domain2.com访问area2。

我不知道如何让它与 CodeIgniter 一起工作。假设他注册了www.domain2.com,并将其设置为指向相同的DNS、服务器等。当访问URL www.domain2.com时,如何让CodeIgnitor执行控制器area2?

也许改变$config['base-url']?路由? .htaccess?如果您已经解决了这个问题,请提供所涉及的代码示例,我们将不胜感激。

编辑:我将放置我想要获取的网站的示例。

我有一台正常安装的CodeIgniter(外部主机,无法访问httpd.conf)它在一台机器上,并且站点的根目录应该通过www.domain1.com访问

所有域是在外面注册的。所以我有主控制器,它向我显示主页视图。假设该站点有 3 个区域 /area1、/area2 /area3,以及它们相应的控制器,显示这些区域的视图。

我的客户想要强调其中一个区域,即控制器 /area2 显示的区域,并且他想要为该区域使用不同的域,www.domain2.com

我可以做什么,以便当用户浏览到 www.domain2.com 时,CI 将它们重定向到 www.domain1.com/area2?例如,我可以根据收到的 URL 修改 $config['base_url'] 吗?或者这是不可能的?我需要修改 .htaccess 文件吗?

I'm not a very experienced programmer, and am using CodeIgniter for second time.

Suppose I have www.domain1.com. So I will have, say 3 controllers /area1, /area2, /area3. Users can access them as www.domain1.com/area1 etc. if I set the base URL as www.domain1.com. But my problem is, the client wants a certain area of the web, say area2, working as a microsite, in its own domain, so he wants to access area2 with www.domain2.com.

I don't know how to get this working with CodeIgniter. Suppose he registers www.domain2.com and set it pointing to the same DNS, server etc. How can I get CodeIgnitor to execute the controller area2 when the URL www.domain2.com is accessed?

Maybe changing $config['base-url']? Routing? .htaccess? Please, if you have solved this, examples of code involved would be greatly appreciated.

Edit: I will put example of the site I want to get.

I have one normal installation of CodeIgniter (external host, I can't access httpd.conf) It is on one machine, and the root of the site should be accessed by www.domain1.com

All domain are outside registered to. So I have the home controller, which shows me the main page view. And suppose the site have 3 areas /area1, /area2 /area3, with their correspondent controllers, showing these areas views.

My client want to emphasize one of the areas, the one that controller /area2 shows, and he want use a different domain for that area, www.domain2.com

What can I do so that when the user browse to www.domain2.com, CI redirects them to www.domain1.com/area2? Could I, for example, modify $config['base_url'] according the received URL, or is that impossible? Do I need to modify the .htaccess file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

≈。彩虹 2024-10-03 03:29:31

经过大量搜索,我找到了一个似乎有效的解决方案,说实话很容易:

修改routes.php

if ($_SERVER['HTTP_HOST']=="www.domain2.com") {
    $route['default_controller'] = "area2"; 
}

不需要mod重写。

After a lot of searching, I found a solution that seems to work, very easy to be honest:

Modify routes.php:

if ($_SERVER['HTTP_HOST']=="www.domain2.com") {
    $route['default_controller'] = "area2"; 
}

No need for mod rewrite.

口干舌燥 2024-10-03 03:29:31

这是一个有用的链接......
http://www.askaboutphp.com /88/codeigniter-setting-up-multiple-sites-on-one-install.html
我自己实际上从未这样做过,但这似乎是无需安装两次 ci 即可完成此操作的方法。祝你好运。

Here's a helpful link....
http://www.askaboutphp.com/88/codeigniter-setting-up-multiple-sites-on-one-install.html
Never actually done this myself, but this seems to be the way to go about it without having two ci installs. Good luck.

独留℉清风醉 2024-10-03 03:29:31

你肯定需要采用 mod_rewrite 方式

you definitely need to go the mod_rewrite way

情痴 2024-10-03 03:29:31

我想到的第一个解决方案是使用 Apache mod_rewrite,但据我所知,它仅适用于内部重定向(即驻留在同一服务器/域上的资源)。

使用 iframe 怎么样?您可以使用全页 iframe 设置 domain2.com 主页,该 iframe 从 domain1.com/area2 获取内容。

the first solution that comes to my mind is to use Apache mod_rewrite, but as far as I know that would work only for internal redirects (i.e. resources residing on the same server/domain).

What about using an iframe? You could set up domain2.com home page with a full-page iframe that takes it's content from domain1.com/area2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文