I am starting a project which it's structure is somehow like a blogging system. Users will use an address like : "username.mydomain.com" to see their profile, and this request should be handeled like they are visiting " mydomain.com/index.php/profile_viewer/username "
First problem is this, when you are sending the request for the subdomain, the host searches between the defined subdomains that are pointing to a directory with the same name. how should I handle all requests to a single file?
And the next problem is how should I get the subdomain name in my php program and pass it to the controller?
I'm just making a wild guess that you're using Apache2 as your web server.
In Apache, you can set up a website (using sites-available) in which all subdomains load a certain set of website files (PHP). For example:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /home/example/public_html
Now when someone goes to a subdomain, like tommy.example.com
Apache will load your set of web files from /home/example/public_html
. You can then identify the subdomain with PHP and/or CodeIgniter using your preferred method (e.g. $_SERVER
).