想在 codeigniter 中创建动态子域?

编程入门 行业动态 更新时间:2024-10-28 14:25:04
本文介绍了想在 codeigniter 中创建动态子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的网站中,我想为用户添加一个功能,以便在域中使用他们的用户名.

In my site i want to add an functionality for user to use their username with domain.

就像现在在 codeigniter 中一样,我想让用户使用他们自己的 url 登录网站并做其他事情.

Like in codeigniter right now i want to give the user to use their own url to login in site and do other stuff.

例如:

我想要 www.username.mysite/login 或 www.username.mysite/category

所以在这里用户可以使用他们的凭据登录并添加类别.所以我的站点中有两个带有登录名和类别的控制器.

so here the user can login with their credential and add the category. so i have two controller in my site with login and category.

那么如何使用路由或 .htaccess 来做到这一点.

So how to do this with the routes Or .htaccess.

推荐答案

在服务器 Vhost 文件中使用此代码:

Use this code in server Vhost file:

<VirtualHost *:80> DocumentRoot "/home/yourdoma/public_html/yourdomain" ServerName yourdomain ErrorLog "logs/yourdomain.local-error.log" CustomLog "logs/yourdomain.local-access.log" common <Directory "/home/yourdoma/public_html/yourdomain"> AllowOverride All Require all Granted </Directory> </VirtualHost> <VirtualHost *:80> DocumentRoot "/home/yourdoma/public_html/yourdomain" ServerName dummy-host.yourdomain ErrorLog "logs/yourdomain-error.log" CustomLog "logs/yourdomain-access.log" common ServerAlias *.yourdomain <Directory "/home/yourdoma/public_html/yourdomain"> AllowOverride All Require all Granted </Directory> </VirtualHost>

以及对于您的 codeigniter 配置文件:

and For your codeigniter config file:

$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; $schema = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'].'://' : ''; $spl_host = explode("mysite", $host); $subhost = ''; if (count($spl_host) == 2) { $subhost = current($spl_host); } if($host == $subhost.'mysite') { $config['base_url'] = $schema.$subhost.'mysite'; } else { $config['base_url'] = $schema.$host; }

更多推荐

想在 codeigniter 中创建动态子域?

本文发布于:2023-11-24 04:00:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623896.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态   codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!