1

Possible Duplicate:
htaccess rewrite for query string

In the url, to view someone's profile, right now, you go to:

http://{url here}/profile/?url={profile url}

My question is, how can I make that:

http://{url here}/profile/{profile url}

Is this possible?

Community
  • 1
  • 1
Justin
  • 19
  • 1

3 Answers3

0

Yes it is possible using .htaccess, here is a tutorial to get you started (check 4th example):

http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html

Bilal Murtaza
  • 785
  • 4
  • 9
  • I have seen this tutorial, but am quite a noob when it comes to htaccess. THANK YOU. Very much, that was exactly what I needed to know. – Justin Jul 03 '11 at 14:10
  • `RewriteEngine On RewriteRule ^/profile/([a-zA-Z0-9_-]+)$ user.php?url=$1 RewriteRule ^/profile/([a-zA-Z0-9_-]+)/$ user.php?url=$1` – Bilal Murtaza Jul 03 '11 at 14:13
0

Assuming you have mod_rewrite installed, it's a simple rule in your .htaccess file.

RewriteRule /profile/([A-Za-z]+)$    /profile?url=$1

The rule assumes your {profile url} variable will always be composed of just characters.

Here's a good article on setting up this functionality if you don't already have it (mod_rewrite, that is).

goggin13
  • 7,876
  • 7
  • 29
  • 44
0

What you're looking for is a rewrite engine. Assuming you're most likely using Apache since you mentioned .htaccess files, you're in luck, as Apache can do the job for you. You'll use Apache's mod_rewrite or mod_alias extensions to get the job done.

http://www.doriat.com/mod_rewrite6.html has a tutorial dedicated to using mod_rewrite specifically with PHP, but you might find the examples on Apache's own site more helpful. http://martinmelin.se/rewrite-rule-tester/ will let you test your rewrite rules as you write them to take a little frustration out of the equation.

UtopiaLtd
  • 2,520
  • 1
  • 30
  • 46