子域的基础上codeIgniter控制器名称 [英] Subdomain based on CodeIgniter controller name

查看:188
本文介绍了子域的基础上codeIgniter控制器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这样两个不同模块的网站,是在两个不同的控制器。像的index.php /控制器1 /...的index.php /控制器2 /...

Suppose I have this two different module for the site that is under two different controllers. Like, index.php/controller1/... and index.php/controller2/...

现在,是有可能有一个子域控制器的网址之一?要清楚,在这个例子中,是有可能有发言权,的index.php /控制器1 /... mainwebsite的URL。 COM /...的index.php /控制器2 /..。像 controller2.mainwebsite.com /

Now, is it possible to have one of the controller URL in a subdomain? To make it clear, in this example, is it possible to have say, index.php/controller1/... in a URL like mainwebsite.com/... and index.php/controller2/... in another URL like controller2.mainwebsite.com/ ?

如果是这样,什么是做到这一点的最好方法是什么? routes.php文件或htaccess的?而在这两种情况下我会AP preciate如何做到这一点,如果你可以点我到相关环节,这也将是有益的一点帮助。

If so, what's the best way to do it? routes.php or .htaccess? And in either case I will appreciate a little help on how to do it, if you can point me to a relevant link, that will also be helpful.

推荐答案

在我看来,你想要做的是一个有点傻,但我想这不是我的地方说。

In my opinion, what you're trying to do is a bit silly, but, I guess it's not my place to say.

下面是你的选择,据我看到它:

Here are your options as far as I see it:

修改Apache配置或.htaccess文件中使用mod_rewrite呼叫重定向到一个特定的子域到一个特定的控制器:

有关实例(我没有测试过这一点):

For instance (I haven't tested this):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog.example.com$
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/blog/$1 [L]

这至少应该点你在正确的方向,我想。当然,这是假定你的子域名指向同一个IP地址和Apache虚拟主机设置为指向该子域相同的目录中正常的域。

That should at least point you in the right direction, I think. Of course, this assumes that your subdomain is pointed to the same IP address and the apache virtual hosts are setup to point that subdomain to the same directory as your normal domain.

你还需要指向所有链接到的子域,省略控制器。所以,如果URL通常是: http://www.example.com/blog/cat/awesome 的那么你需要做的链接指向 http://cart.example.com/cat/awesome 。所以,你不会是能够再使用了漂亮的辅助功能,如 SITE_URL('车/ CAT /真棒') - 这将是一个重大转机关闭对我来说。

You'll also need to point all your links to the subdomain and omit the controller. So, if the URL would normally be: http://www.example.com/blog/cat/awesome then you'll need to make the link point to http://cart.example.com/cat/awesome . So, you're not going to be able to use the nice helper functions like site_url('cart/cat/awesome') anymore--that would be a major turn off for me.

我希望是有道理的。

设置你的CI实例支持多个应用程序,只是有子域指向相应的应用程​​序目录

有关详细信息:<一href="http://$c$cigniter.com/wiki/Multiple_Applications/">http://$c$cigniter.com/wiki/Multiple_Applications/

做一些疯狂的东西与Route类:

在您routes.php文件的配置文件:

In your routes.php config file:

if(preg_match('/^blog/',$_SERVER['HTTP_HOST'])) {
    $route['(:any)/(:any)/(:any)/(:any)'] = 'blog/$1/$2/$3/$4';
    $route['(:any)/(:any)/(:any)'] = 'blog/$1/$2/$3';
    $route['(:any)/(:any)'] = 'blog/$1/$2';
    $route['(:any)'] = 'blog/$1';
    $route['blog'] = 'blog/index';
}

如果您的任何页面都需要4个以上的URI部分,添加另一线的路线规则的顶部。我甚至不知道这会的工作,本身......但它可能。我一定给它一个镜头,因为这将是最少的工作更有可能。

If any of your pages require more than 4 URI parts, just add another line at the top of the route rules. I don't even know if this would work, per se... but it might. I'd definitely give it a shot as it would be the least amount of work more than likely.

这篇关于子域的基础上codeIgniter控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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