.htaccess重定向codeigniter子域

时间:2013-07-04 19:35:34

标签: .htaccess codeigniter subdomain

我的网站有这样的网址结构:

和CodeIgniter路由文件

$route['sign-up'] = 'members/signup';
$route['blog']    = 'blog/home';

我想改为:

我的主机文件没问题:

127.0.0.1       www.mywebsite.com
127.0.0.1       mywebsite.com
127.0.0.1       blog.mywebsite.com
127.0.0.1       signup.mywebsite.com

我尝试了很多关于RewriteCond和RewriteRule的技巧,但我找不到好的搭配...

感谢的!

1 个答案:

答案 0 :(得分:3)

我认为您甚至可以轻松“破解”您的config/route.php文件,甚至无需修改.htaccess:

if ($_SERVER['SERVER_NAME'] == 'blog.mywebsite.com') {
    $route['default_controller'] = 'blog/home';
    // Other routes to your blog
} elseif ($_SERVER['SERVER_NAME'] == 'signup.mywebsite.com') {
    $route['default_controller']    = 'members/signup';
    // Other routes for your signup
}