Stanley Ngumo
Stanley Ngumo

Reputation: 4249

Directly adding username to URL PHP

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

Upvotes: 1

Views: 2809

Answers (5)

Neil Aitken
Neil Aitken

Reputation: 7854

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

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157989

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]

Upvotes: 2

gurun8
gurun8

Reputation: 3556

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

Upvotes: 0

Tarka
Tarka

Reputation: 4043

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.

Upvotes: 3

Adam Hopkinson
Adam Hopkinson

Reputation: 28793

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

Upvotes: 1

Related Questions