在我的网站中,我想为用户添加一个功能,以便在域中使用他们的用户名.
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 中创建动态子域?
发布评论