Matteo Cardellini
Matteo Cardellini

Reputation: 896

Folder with Get value

Could someone with more experience than me explain how it works the link (for example):

http://www.facebook.com/zuck  

I think it's the same thing of this

http://www.facebook.com/profile.php?id=4

I imagine that "zuck" is a GET type string but I don't understand how I can do the same thing.

Thank You very much

Upvotes: 2

Views: 84

Answers (3)

Starx
Starx

Reputation: 79021

Actually, i am not sure about it, but by the way I see it, facebook probably uses both ways to get to a profile

I quick .htaccess to make sure all the request arrive on same page.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?input=$1 [L]

Now, in the profile.php, it should do a simple check like

$input = $_GET['input'];

if(is_string($input)) {
 // then retrieve profile id, based on the string
}
//now either way you have an unique identifier at last
//
//
// use your logic further more

Upvotes: 1

SáT
SáT

Reputation: 3692

You can do it easily with Apache's mod_rewrite module: it's a mechanism that allows you to specify what content to serve for an incoming request. For example, you could make a rule, in your .htaccess file, like this:

RewriteRule (.*) index.php?req=$1

which would then redirect every incoming request to a central index.php, where you could parse the requested URI (in your example, the req variable would hold the value "zuck"), then you could serve some content based on that information (e.g. you could look up "zuck" in a database containing user profiles, grab the id associated with the "zuck" value, then show the profile for user #24).

At least that's the basic idea. It's usually called "URL prettifying" or "friendly URLs" or "SEO URLs", search around these terms and you'll find plenty of resources.

Upvotes: 2

ilya iz
ilya iz

Reputation: 470

.htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?id=$1 [L]

Upvotes: 2

Related Questions