Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created an application in PHP, I would like to re-direct the following URL to corresponding sub-domain.

Dynamic URL pattern:


I wish to re-direct this to the corresponding sub domain:

  1. How do I create a rewrite rule for this purpose?
  2. How do I register DNS for sub-domain without using CPANEL? (I want to activate sub-domain when the user registers to the system.)
share|improve this question
Are you sure you want to have subdomain testuser with host www in it, not host testuser in base domain? – Lazy Badger Oct 27 '11 at 9:24
@Lazy Badgemydomain is the main domain and testuser is the sudomain. – Abdul Majeed Oct 27 '11 at 9:30
for which task you want to give domain to user? It's possible, just can't see reasons – Lazy Badger Oct 27 '11 at 9:47
I want to give personalized site for each user.They can edit their page. – Abdul Majeed Oct 27 '11 at 10:43
"site" is host, not domain. Learn correct terms! www isn't mandatory in site-name - it's same hostname, as others - you just make sitename unnesessary long and complex – Lazy Badger Oct 27 '11 at 12:24

Take a look at this thread over at webmaster world

You'll need to create:-

  • A DNS mapping: *.yourdomain.com => your IP
  • A server alias *.yourdomain.com in your virtualhost configuration

.htaccess file with something like:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^user\.example\.com [NC]
RewriteRule ^(.*)$ /user [R=301,L] 

You can replace user with ([a-z]) and use it in the rewriteRule. That way you can have a general mapping: something.yourdomain.com => yourdomain.com/user, even if the user isn't signed up to your site.

share|improve this answer

You need to use a wildcard DNS rule for the subdomains, then you can do a rewrite rule to redirect that link to the correct domain.

Information on this can be found here: http://www.thecpaneladmin.com/setting-up-wildcard-dns-with-cpanel/

You will need access to the configuration files so it may not be easy depending on your host and hosting plan.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.