Score:0

Subdomain in nginx with codeigniter

cn flag

So currently all users profile page are loaded on path https://example.com/username. i want to change that and load user profile page on https://username.example.com.

i am using nginx as web server,below is the server block i have tried

server {
    listen 80;
    server_name *.example.com;
    if ($host ~ "^(.*)\.example\.com$") { set $subdomain $1;}
    rewrite ^ $scheme://example.com/$subdomain$request_uri permanent;
}

this redirects anyone who visit *.example.com to https://example.com/username which is my controller in CodeIgniter. is there a way to keep the url as username.example.com and load serve the content from https://example.com/username

Michael Hampton avatar
cz flag
Don't attempt to do rewrites in nginx. You need to handle this in your PHP code.
Dhrumil Patel avatar
cn flag
@MichaelHamptop i have no idea how to do that can you share with me an example ?
Michael Hampton avatar
cz flag
We don't do programming questions here. You can ask programming questions on [so].
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.