Welcome Guest, Not a member yet? Register   Sign In
Add a dynamic sub-domain for every user
#1

[eluser]Hitankar[/eluser]
Hi,

I am developing an application. I need to have the following.

For the user 'Ray'. The url should be:

http://www.ray.example.com/site/

redirect to

httpo://www.example.com/site/users/ray

where site is a controller, users is a method and the third segment is the username.

Is this possible through routes or would be needing to do some changes to .htaccess.

Thanks Ray
#2

[eluser]Clooner[/eluser]
Setting up subdomains is done using vhosts! You might want to look into that! Once you have that setup it's not that hard to create a forwarder to the correct url using either apache or php. You will probably also be able to run the app under the subdomain.
#3

[eluser]Hitankar[/eluser]
I do not wish to run the app under a sub-domain. I just want the url to look like a subdomain which redirects to a particular codeigniter url.
#4

[eluser]WanWizard[/eluser]
Not always.

If you have a limited about of (static) subdomains, that's the way to go. If your subdomains are dynamic, vhosts won't help you. You don't want to modify the config and restart Apache everytime a website admin creates a new user.

There are two options:
Use mod_vhost_alias, which is what ISP's use for mass vhosting. This allows you to dynamically link a subdomain to a disk location. You still have to make sure all subdomains end up at the same code, so you might want to create symlinked directories when a new user is created in the application.
You can also forget about vhosts, and use a dedicated IP for your application.

Make sure DNS points to that IP so all requests arrive at your application. To make that dynamic as well, use DNS wildcards. That means you have to use <user>.example.org, not www.<user>.example.org, as wildcards have to be at the left, and on their own.

In both cases you can either use mod_rewrite or PHP code to deal with all the different hostnames arriving at your application.
#5

[eluser]WanWizard[/eluser]
[quote author="Hitankar" date="1276257978"]I do not wish to run the app under a sub-domain. I just want the url to look like a subdomain which redirects to a particular codeigniter url.[/quote]
In that case just capture all subdomains using mod_rewrite.
#6

[eluser]mddd[/eluser]
There are two sides to this story. First, your server has to know what to do when a request comes in for a certain subdomain. For that purpose, you need to set your web server so that it just handles request for all subdomains. That is done in a vhost or similar file like clooner says. You can try if it works: if it is set correctly, a request for somename.yoursite.com should get you just the same result as a request for yoursite.com.

Then, the second step is to check which domain was requested. You can use .htaccess for that. For example:
Code:
RewriteCond %{HTTP_HOST} ^([^.]+)\.yoursite\.com$ [NC]
RewriteRule ^.*$ /site/users/%1 [L]




Theme © iAndrew 2016 - Forum software by © MyBB