serving different content based on the domain in codeigniter

爷,独闯天下 提交于 2019-12-23 05:26:35

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3896162/serving-different-content-based-on-the-domain-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!