Search code examples
phpcodeignitercodeigniter-routing

CodeIgniter: Redirect URL with subdomain


I am trying to redirect a subdomain URL to a controller method. Complete url is

http://subdomain.domain.com/urlofservice/servicename.svc

Part1 I have configured subdomain from hosting service's control panel. Which is redirecting subdomain.domain.com to domain.com

Part2

Configured route url on router.php as

$route['urlofservice/servicename.svc'] = "test/test3";

But when I try to hit the complete url, I get 404 error from the hosting service. 404 error is thrown from hosting server not from codeigniter.
Is there any problem with my seetting?
Should I change redirection setting in .htaccess or in server control panel? Right now server is throwing 404 error which means it's not even hitting the application yet.


Solution

  • You can't use routes directly for subdomain. Use this in your routes.php

    if (strstr($_SERVER['HTTP_HOST'], 'subdomain.domain.com')) {
       $route['urlofservice/servicename.svc'] = "test/test3";
    }