Forum Moderators: phranque

Message Too Old, No Replies

how to map a querystring to subdomain

         

swetamakode

11:46 am on May 12, 2010 (gmt 0)

10+ Year Member



Hello,

In my website I used to show the url like http://www.example.com/user/page.php which i had done using mod_rewrite in .htaccess file,originally the url is like
http://www.example.com?uid =user&pid=page.php

but now the client had asked me for the url like

http://www.user.example.com/page.php

Is it possible to get it by URL Mapping and using the concept of virtual subdomain or do I have to introduce the concept of subdomains creation in my website to get it done.

Please reply asap.

Thank you.

[edited by: jdMorgan at 1:35 pm (utc) on May 12, 2010]
[edit reason] Please use "example.com" [/edit]

jdMorgan

1:46 pm on May 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can easily 'map' username-subdomains to filepaths using mod_rewrite, but there are several requirements:

1) The server must have a unique IP address. It must be an IP-based virtual server, not a name-based virtual server. Otherwise, you will have to use the control panel to add each "user" by hand, your hosting account may limit these "add-on domains" to a very few, and you will not easily be able to share scripts between users and/or the "main site."

2) You must define a "wildcard subdomain" record in your DNS zone file, to map requests for all possible subdomains to the IP address of your server.

Further, note that www.username.example.com is a sub-sub-domain. You'd be far better off using username.example.com instead of www.username.example.com or username.www.example.com.

The only (minor) complication is that you cannot allow a user to sign up with a username of "www." But since you must also check that usernames contain only characters which are valid in the subdomain field of an HTTP request (only lowercase letters in any position, digits 0 through 9 in any but the first position, and hyphens in any but the first or last position), this added requirement is rather trivial.

A search of WebmasterWorld for "rewrite subdomain subdirectory RewriteCond HTTP_HOST" will likely turn up many useful threads.

Jim