tags:

views:

83

answers:

5

Hi,

I would to know how one is able to append a username directly to a site url without having to put it within a query?

Eg

www.myspace.com/micheal

instead of

www.myspace.com?name=micheal

Without having to create a new folder for the user so that when the url is typed including the name, the surfer is taken directly to the user's profile.

Thanx

+1  A: 

This is called url rewriting, and is handled by mod_rewrite on Apache servers.

A rewrite rule takes the incoming uri, parses it and rebuilds it into what the script needs to run.

A very simple example:

RewriteRule ^michael$ /?name=michael$

There's lots on Google when you know where to look. Start here:

http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

adam
+3  A: 

If you're using Apache, which, using PHP, you most likely are, look into mod_rewrite. This lets you do things like this, where www.myspace.com/micheal would be translated internally to www.myspace.com/?name=micheal before being sent to the scripts.

Take a look here http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html for the documentation on how to use it.

Slokun
+1 for providing the link to the 2.2 docs, not the 1.3
Felix
@Felix does it really matter?
Col. Shrapnel
@Col. Shrapnel Yes.
Felix
@Felix care to give an example, according to this very question?
Col. Shrapnel
@Col. Shrapnel I can't, but that's the point. The differences are mostly pretty subtle and that subtlety is what is going to give you incredible headaches. I'm not "just saying" this, I banged my head against such subtleties quite a few times before, just can't remember what they were.
Felix
A: 

I think you might be referring to "Pretty URLS" which is generally setup on a web server level using something like Apache mod_rewrite:

gurun8
+1  A: 

For the Apache web-server .htaccess file with the following code will do the thing.

RewriteEngine on
RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$ index.php?name=$1 [QSA,L]
Col. Shrapnel
@Stanley please note it will bring any url entered, even `micheal/some/anything/`, so further filetring is needed
Col. Shrapnel
+1  A: 

As everyone has pointed out you want URL Rewriting.

If you are using IIS rather than Apache, there are still a couple of options.

Free Option - Ionics Isapi rewrite filter

Commercial Option - Isapi_Rewrite

Neil Aitken
+1 for IIS, rather than Apache
Slokun