Reputation: 5
you all know that if you login to your Facebook or Twitter account, you see a URL on address bar like this: https://web.facebook.com/iamakm15. That means your username appears on URL. My question is, how Facebook and Twitter did this? I mean what programming language did they use to show the username in the URL?
Now, when I login to my profile, I get a URL like this: http://localhost/AKM.PHP/project_akm/profile.php, so how can I add username after profile.php like this: /profile.php/imakm15 to my URL?
Upvotes: 0
Views: 346
Reputation: 120
Later later edit ( didn't have space for full explanation in comment)
Ok, good. Let's start with the beginning. When you don't have rewrite setup on yoru server, your link will look like this:
http://localhost/AKM.PHP/project_akm/profile.php?username=iamakm15
Profile.php will extract the parameter with $_GET['username'] in your php code, it will make a query in database, where clause username='iamakm15' and it will extract the info associated with 'iamakm15'. If this step is already done and it works, in your root localhost ( you need to place this file at this level:localhost in order to work), add a file called '.htaccess' - if you already have one, just add these lines:
RewriteEngine On
RewriteBase /
RewriteRule ^AKM.PHP/Project_akm/([^/\.]+)/?$ /AKM.PHP/Project_akm/profile.php?username=$1 [L]
After saving this file, just try to access url:
http://localhost/AKM.PM/project_akm/iamakm15
and you should see the page with info about user: iamakm15. Make this exercise with different usernames from database, by modifying iamakm15 with other one.
if you get a 500 error you can add a new rule ( after RewriteBase / ):
RewriteRule ^/AKM.PHP/Project_akm/profile\.php$ - [L]
because can match itself after redirect.
Upvotes: 1