Server Fault is a question and answer site for system and network administrators. 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 want to point to

With "subdomain" varying with user input

How do you do that? Also, I want it to be a silent redirect, so the is shown in the adress bar when the user types it or clicks on a link

share|improve this question

migrated from Jan 3 '10 at 22:59

This question came from our site for computer enthusiasts and power users.

See this one: You will actually need

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} !$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+) [NC]
   RewriteRule (.*) [L]

EDIT: to have a "silent" redirect, the last rule should be:

   RewriteRule (.*) /profile.php?user=%2 [L]

Make sure you have the profile.php in the directory where the DocumentRoot of the wildcard is set to.

share|improve this answer
Thanks, that sort of worked except when I type in the URL it does a physical redirect instead of a silent one What I want is for the subdomain to remain in the address bar so the users won't know theres a redirect – Ryan Jan 3 '10 at 16:34
@Ryan, then you can call the "profile.php" from your subdomain, e.g. make equal to calling Edited my post to describe the solution. – naivists Jan 3 '10 at 16:51

I've not done this myself, but I'd start by:

  1. With your DNS provider, configure the wildcard.

    * IN A

  2. Use Apache's mod_rewrite to inspect the Host: header and modify the URL to match your specs.

share|improve this answer

The solution is probably a mix of all the mentioned solutions.

First you will need the DNS entries as mentioned by JJ. Then you have to use the ServerAlias directive to make all subdomains pointing to the same directory. And at the end you could use the first 2 lines of Niek Bergman's code:

$domain = explode(".", $_SERVER['SERVER_NAME']);
$username = htmlentities($domain[0]);

And from there on you can do with $username whatever you want.

share|improve this answer

Your Answer


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