CodeIgniter Forums
Help with subdomain routing - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Help with subdomain routing (/thread-60206.html)



Help with subdomain routing - El Forum - 02-05-2014

[eluser]Unknown[/eluser]
I'm trying to setup a blog script on a website running on the CodeIgniter framework. I want do this without making any major code changes to my existing website's code. I figured that creating a sub domain pointing to another Controller would be the cleanest method of doing this.

The steps that I took to setup my new Blog controller involved:

Creating an A record pointing to my server's ip address.
Adding new rules to CodeIgniter's routes.php file.
Here is what I came up with:

Code:
switch ($_SERVER['HTTP_HOST']) {
    case 'blog.notedu.mp':
        $route['default_controller'] = "blog";
        $route['latest'] = "blog/latest";
        break;
    default:
        $route['default_controller'] = "main";
        break;
}

This should point blog.notedu.mp and blog.notedu.mp/latest to my blog controller.

Now here is the problem...

Accessing blog.notedu.mp or blog.notedu.mp/index.php/blog/latest works fine, however accessing blog.notedu.mp/latest takes me to a 404 page for some reason...

My .htaccess file looks like this (the default for removing index.php from the url):

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

And my Blog controller contains the following code:

Code:
class Blog extends CI_Controller {

    public function _remap($method){
        echo "_remap function called.\n";
        echo "The method called was: ".$method;
    }

    public function index()
    {
        $this->load->helper('url');
        $this->load->helper('../../global/helpers/base');

        $this->load->view('blog');
    }

    public function latest(){
        echo "latest working";
    }

}

What am I missing out on or doing wrong here? I've been searching for a solution to this problem for days Sad I have also started a bounty on this question on stackoverflow and if someone does come up with a solution to this problem I will reward the bounty to you on there.


Help with subdomain routing - El Forum - 02-05-2014

[eluser]Massaki[/eluser]
Your server must understand that if you call 'blog.notedu.mp', it has to redirect to your 'blog' subfolder.

In your root folder, create/edit .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.notedu\.mp$ [NC]
RewriteRule ^(.*)$ http://notedu.mp/blog/$1 [R=301,L]