tags:

views:

18

answers:

1

Hi,

First of all, sorry if I got the term 'pseudo subdomain' wrong. what I am trying to achieve is this-

When someone registers on my application, they get a new url like.. yourname.myapp.tld

I dont want to use the subdomain system for this. To be frank, I dont know how the subdomains exactly work but it guess it requires a folder per subdomain inside the document root and then the server redirects the requests there.

Can this be achieved by doing something like -

when a visiter types any subdomain, (anything.myapp.tld), he is able to access myapp . In the index.php file i will explode the $_SERVER['HTTP_HOST'] to get the subdomain which i will store in session and will thereafter act as an identifier for that user. Ideally i wouldnt want to create any vhosts or add many lines to the hosts file. Can this be achieved with just one vhost?

Is this possible with mod rewrite or something ?

A: 

Yes you can archive this using wildcard that needs to be configured on both, the dns server and http server

On the dns a entry like this (installing dns on ubuntu https://help.ubuntu.com/10.04/serverguide/C/dns.html):

; wildcard subdomains are all directed to this IP
;  of course this should be the IP of your web server
*.domain.tld.      IN  A    1.2.3.4

At apache an entry like this:

<VirtualHost 111.22.33.55>
    DocumentRoot /www/subdomain
    ServerName www.domain.tld
    ServerAlias *.domain.tld
</VirtualHost>

What happens after is that everything.domain.tld will be going to your main folder so you can use the index.php to redirect it to the right place or even an htaccess using mod_rewrite.

Prix
Hi, dont know much about the dns server. Got the apache server part. What if i want to try this on ubuntu desktop for now? something will go into the hosts file if i m not wrong. tried the following but didnt work127.0.0.1 domain.tld *.domain.tld Thanks
naiquevin
i am not sure if you can do it from the hosts file but it would be:10.0.0.1 *.domain.tld aliasTry setting up a local DNS on your ubuntu using BIND (named) which is what most server out there use.
Prix
OK, found this, http://vlaurie.com/computers2/Articles/hosts.htm you can't do it from the Hosts file it seems :)
Prix
updated the reply with the link to ubuntu dns how to docs.
Prix
Thanks for the useful links.
naiquevin
My pleasure anything let me know...
Prix