Question

I'm going to develop a website in codeigniter. But not sure if the methor i'm going to use is the best approach. There will be many addon domains for the same site. But content will be filtered based on the domain used to visit the site.

For Example If a user comes from the domain siteusa.com then the content will be shown filtered accordingly specific user. If the user comes from siteuk.com/sitechina.com the content will be filetered accordingly etc...

I'm planning to do something like this to detect the url and serve content

 $ref = getenv("HTTP_REFERER");
    echo $ref; 

Another problem I see is the baseurl setting of codeigniter, but i saw a solution for that here

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://www.your-site.com/
|
*/

if(isset($_SERVER['HTTP_HOST']))
{
$config['base_url'] = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$config['base_url'] .= '://'. $_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}

else
{
$config['base_url'] = 'http://localhost/';
}

Is this is the best method to do this? Is there any possible bottleneck I may get into?

The main domain of the site will be serving unfiltered content and each addon domain will filter it according to filter set for each domain from backend.

Was it helpful?

Solution

Are .htaccess rules an option for you perhaps? Note that CI also has the routes.php file for fine-grained control over URLs, but not at the domain level I think.

OTHER TIPS

I don't see any issue in doing it this way. This won't cause a bottleneck, as the additional functions have negligible overhead.

For what it's worth I'm doing the same thing for a SaaS service I run where multiple websites (thousands) are pointed to the same code igniter installation. I haven't had any issues.

As for the filtering, just make sure that you have proper indexes setup as you will need to query by the HTTP_HOST variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top