tags:

views:

27

answers:

4

Hi, it's been a very very long while since i did anything in PHP. Would anyone care to explain how to achieve such effect:

i go to mydomain.com/user/peter and get a customized user page for this username 'peter' can it work such that peter gets piped to some php script that generates page for user parameter? it kind of works like passing parameter via url but looks nicer, how is this thing called?

(i know that this sounds weird but i'm sure you advanced php coders will know what i'm asking about)

thanks peter

+1  A: 

You are talking about URL rewriting. You need .htaccess and mod_rewrite.

code_burgar
To the downvoter: since the answer specifically answers the OP's question, namely "it kind of works like passing parameter via url but looks nicer, how is this thing called?" the downvote vas totally uncalled for.
code_burgar
@code_burgar - nevermind the haters. +1
Byron Whitlock
+3  A: 

If using Apache, mod_rewrite can solve this:

RewriteEngine on
RewriteRule /user/([^/]+) /user.php?name=$1 [B,QSA]

If in an .htaccess file in the root:

RewriteEngine on
RewriteRule user/([^/]+) user.php?name=$1 [B,QSA]

See the docs for mod_rewrite.

You can also enable MultiViews and then those requests will be mapped to user.php automatically. You can access the value after user with $_SERVER['PATH_INFO]`:

Options +MultiViews

See the docs for content negotiation.

Artefacto
A: 

You're looking for .htaccess mod_rewrites.

http://devmoose.com/coding/20-htaccess-hacks-every-web-developer-should-know-about

Basically you want to write a rule that sends all URLS of user/peter to user.php?username=peter. From there you can manipulate with php echo $_GET['username'];

bradenkeith
A: 

I know this was answered already, but IIS users (like myself) can use URL Rewrite 2.0 to accomplish the same task with Regular Expressions. I've installed it and it works well.

Dutchie432