In my site i want to add an functionality for user to use their username with domain.
Like in codeigniter right now i want to give the user to use their own url to login in site and do other stuff.
For eg:
i Want www.username.mysite.com/login
or www.username.mysite.com/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.
So how to do this with the routes Or .htaccess.
Use this code in server Vhost file:
<VirtualHost *:80>
DocumentRoot "/home/yourdoma/public_html/yourdomain"
ServerName yourdomain.com
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.com
ErrorLog "logs/yourdomain.com-error.log"
CustomLog "logs/yourdomain.com-access.log" common
ServerAlias *.yourdomain.com
<Directory "/home/yourdoma/public_html/yourdomain">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
and For your codeigniter config file:
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
$schema = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'].'://' : 'http://';
$spl_host = explode("mysite.com", $host);
$subhost = '';
if (count($spl_host) == 2) {
$subhost = current($spl_host);
}
if($host == $subhost.'mysite.com') {
$config['base_url'] = $schema.$subhost.'mysite.com';
} else {
$config['base_url'] = $schema.$host;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With