2

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

Smamatti
  • 3,901
  • 3
  • 32
  • 43
Matteo Cardellini
  • 876
  • 2
  • 17
  • 41
  • 1
    Search for `.htaccess` in your favorite search engine (or on stackoverflow) – knittl Mar 03 '12 at 14:04
  • It's not a parameter in the perfect sense. It's work like you would be accessing a folder or file on your webserver, but the configuration redirects you to a specific site. This can be done via `.htaccess` file but isn't the only option to do this. – Smamatti Mar 03 '12 at 14:08

3 Answers3

2

.htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?id=$1 [L]
ilya iz
  • 470
  • 1
  • 6
  • 19
2

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.

SáT
  • 3,633
  • 2
  • 33
  • 51
1

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
Starx
  • 77,474
  • 47
  • 185
  • 261