I have a question that I can't seem to find a satisfactory answer to by searching the site, and I'm not entirely sure I am searching with the correct keywords.

Anyway, here goes.

I am working on a free membership script, and would like to use the members username as part of the url.

What I would like is for it to be


I know this format is for sub-domains, and if I had a way to automate the creation of a sub-domain for each member, I would do that, but my host says that I can't do that.

So, what I would like to see happen is for it to go to the index page of domainname.com, and extract that username to be assigned to a variable, so that from that point on it would be carried through the site in a session variable.

I guess basically my questions are:

Will it get to the domainname.com/index.php and is there a way to take the username from the front of the domain name?

If this is possible, what I need to know is how to extract just the username on the index page and assign it to a variable, and where should that happen?

The page will start out with:

session_register("memid_session"); (this is a guess on my part)

include "config.php";

Hope all this makes sense, and that there is a simple solution, even if it is totally different then what I am asking.

I would just like to avoid appending the username to the end of the url and using mod_rewrite to capture it. (for alot of reasons including not understanding mod_rewrite).

Thanks in advance.

You can use htaccess to capture xxx.example.com and redirect it to www.example.com/index.php?sub=xxx

RewriteCond %{HTTP_HOST} ^(.*).example.com 
RewriteCond %{HTTP_HOST} !^www.example.com [NC] 
RewriteRule ^(.*)$ http://www.example.com/index.php?sub=%1 [P]

Thank You pritaeas for your response.

I just tried the rewrite code that you sent, but it doesn't seem to have any effect.

here is the .htaccess file

RewriteCond %{HTTP_HOST} ^(.*).ehome-team.com
RewriteCond %{HTTP_HOST} !^www.ehome-team.com [NC]
RewriteRule ^(.*)$ http://www.ehome-team.com/index.php?sub=%1 [P]
ErrorDocument 404 http://www.ehome-team.com/404page.php

The errordocument 404 still works fine for any erroneous web pages as long as the domain is correct, but put anything before the domain, other then www, and it gives me a server not found error.

Any idea why, or suggestions on how to get around this?


It appears that it is being seen as a sub-domain which doesn't exist, which is why it is giving me the 'server not found' error.
So, it isn't even getting to the .htaccess file to do the Rewrite.
Is there another way to accomplish this?

To be honest, simply doing www.domainname.com/username/ would be much simpler.

I beg to differ and say it's just as simple to get a subdomain for the user as it is for a subdirectory. I just happened to come across this issue a couple of years ago and already know the answer provided you use cpanel. In cpanel delete all of the subdomains for the domain your going to use for this project then create a subdomain called '*' (without the quotes). So just a * is the subdomain. Then point the subdomain to a directory which will process all of the subdomains. In that directory you should have a brand new blank index.php ready to create. Now with that one subdomain, any subdomain you enter will point to that index.php file. All you need to do is find out what the subdomain is and fetch relative content from the database. To make things easier, php stores the domain information in $_SERVER; Or at least one of those $_SERVER variables. So using that variable you can substr() to your subdomain and find out from the database which user owns the subdomain and which content should be displayed for that subdomain.

So that's a brief overview of how it works and any questions just post away.

commented: This is EXACTLY the kind of response I was looking for... thank you +0

This sounds like the answer (at least one option) that I was looking for.

I am going to give this a try to see how it works.

But I will come back to report the results, and to mark the thread Solved, if it does in fact resolve the issue.


And BTW, I do know that using domainname.com/username/ would be just as easy, but I just prefer the structure of username.domainname.com
It looks more professional to me, and less like an affiliate/member link. Just my opinion...

Unfortunately, I just realized that I don't have cPanel.. My host provides WHM.

So, after a long discussion with them and having them try to create the '*' sub-domain it was decided that it wasn't going to work...

Guess that means that I am stuck (for the moment) with the format that I really just didn't want to use


Thanks for everyone's help.


commented: Thanks for the update +6