views:

45

answers:

2

lets says I have a domain example.com and I have wildcards dns switched on. on example.com a user can signup with username and password. once registration is done, username.example.com starts redirecting to example.com/script/script.php?user=username. address bar would still show username.example.com

what would be the contents of the .htaccess file to accomplish this?

I have zero expertise with mod_rewrite. please advise. thanks and regards.

+1  A: 

You need more than mod_rewrite for this - you also need to read-up on apache virtual hosts.

Xeoncross
No, you don't. Apache virtual hosts are really just another, easier way to do URL rewriting.
Artelius
A: 

Assuming your host is configured to serve up all hostnames from the same DocumentRoot, then you'd want something a lot like this:

RewriteEngine On
#If Not Match example.com and Not Match www.example.com
RewriteCond %{HTTP_HOST} !^example\.com
RewriteCond %{HTTP_HOST} !^www\.example\.com
#then rewrite according to this rule
RewriteRule ^(.*)$ script/script.php?user=%{HTTP_HOST}

If you're on shared hosting and can't specify a debug-log file, do your own tests on a test server you have access to.

Artelius
looks good. is this all I need in my .htaccess?
Priyo
Pretty much, though I haven't tested it so it may not be totally correct.
Artelius