Harry
Harry

Reputation: 735

Vanity URLS & Xampp

I understand that there may be other questions regarding vanity urls but everyone i see has a different code that i guess does the same job. Therefor i do not understand what rules are best for my personal question, that being said here is my question.

I simply want to create this,

127.0.0.1/website/profile.php?id=1

To this,

127.0.0.1/website/profile/Admin

My sub questions are also,

  1. I understand the .htaccess file has to be in the root directory, but is that the root of my website or my xampp htdocs?(e.g c:/xampp/htdocs/ or c:/xampp/htdocs/website)
  2. Using php should i make the conversion between id to username for the URLS on a seperate file then redirect to the requested user's page?

Thank you for reading, i just can't seem to get my head around .htaccess!

Upvotes: 0

Views: 394

Answers (1)

Ayman Safadi
Ayman Safadi

Reputation: 11562

  1. Root directory of your website.
  2. No need for redirects. The way it works is that you can map every section of your URL to a URL parameter. For example, http://localhost/profile/Admin is really interpreted as http://localhost/website/profile.php?username=Admin. Only users will see the vanity URL; PHP will still see the URL parameters. In your case, the .htaccess rule will look something like ^profile/([0-9]+)$ profile.php?username=$1 (I obviously don't know for sure since I don't know the architecture of you site).

On a side note you might find Virtual Hosts interesting. It's a way of being able to create your own local domain for your site, for example http://my-local-website instead of using http://localhost/website or waiting to test in production.

More info here: http://sawmac.com/xampp/virtualhosts/

Upvotes: 1

Related Questions