Change URL Address make short in PHP
Asked Answered
P

3

5

I have Url as:

localhost/ab/directory.php?id=200

id=200 is jenny id member

how to change it to

localhost/ab/jenny

is possible?

Thanks

Pearman answered 11/12, 2009 at 5:34 Comment(4)
Welcome to StackOverflow. Great first question!Barnyard
What webserver you are on? Apache or IIS?Insolvable
How come everyone assume that he is on Apache?Insolvable
@Nirmal: Because his script is named directory.php.Discuss
B
11

You'll want to use mod_rewrite, a module available in apache. This will be managed by an .htaccess file within your web directory. AddedBytes has a nice tutorial for beginners on url-rewriting.

See: http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/

Barnyard answered 11/12, 2009 at 5:37 Comment(1)
this link is brokenMopes
D
1

You can do this in at least 2 different ways:

  • Use mod_rewrite for Apache to map the SEO friendly URL to your querystring based URL.
  • Make /ab a php script that inspects the PATH_INFO to retrieve /jenny. You'll have to configure Apache to treat scripts with no extension as php scripts for this to work.
Discuss answered 11/12, 2009 at 5:39 Comment(4)
i interest for ponit 2. 'localhost/ab/directory.php?id=200', sorry 'ab' is my project. sample: i have home.php, in home.php i call localhost/ab/directory.php?id=200 using href. and then i wan to direct to directory.php, but i want to change in address bar be 'localhost/ab/jenny'. in directory.php, only get jenny and call mysql to get detail name,address, etc. Can you give sample for point 2, sorry my english bad.thank youPearman
@Iwan: I'm sorry, in order for option 2 to work, /ab would have to be an actual php script, not a directory as it is in your case. I suggest you go with option 1 as it is the more widely practiced and accepted of the 2 approaches.Discuss
ok. i am so interest your option 2.but my site is running. any problem if i do that? can you give sample for my problem..please.. thank you.Pearman
@Iwan: See the link in @Jonathan Sampson's answer.Discuss

© 2022 - 2024 — McMap. All rights reserved.