根据 codeigniter 中的域提供不同的内容

发布于 2024-09-26 14:41:29 字数 1219 浏览 1 评论 0原文

我将在 codeigniter 中开发一个网站。但不确定我要使用的方法是否是最好的方法。同一站点将有许多附加域。但内容将根据访问该网站所使用的域进行过滤。

例如,如果用户来自域 siteusa.com 然后内容将根据特定用户进行过滤。如果用户来自 siteuk.com/sitechina.com 内容将被相应地过滤等等...

我计划做这样的事情来检测网址并提供内容

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

我看到的另一个问题是codeigniter 的 baseurl 设置,但我在 此处 看到了一个解决方案

/*
|--------------------------------------------------------------------------
| 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/';
}

这是最好的方法吗?我可能会遇到任何瓶颈吗?

网站的主域将提供未经过滤的内容,每个插件域将根据后端为每个域设置的过滤器对其进行过滤。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为人所爱 2024-10-03 14:41:29

.htaccess 规则是否适合您?请注意,CI 还具有对 URL 进行细粒度控制的routes.php 文件,但我认为不是在域级别。

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.

Oo萌小芽oO 2024-10-03 14:41:29

我认为这样做没有任何问题。这不会造成瓶颈,因为附加功能的开销可以忽略不计。

为了值得,我对我运行的 SaaS 服务做了同样的事情,其中​​多个网站(数千个)都指向相同的代码点火器安装。我没有遇到任何问题。

至于过滤,只需确保您有正确的索引设置,因为您需要通过 HTTP_HOST 变量进行查询。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文