1

I want to be able to write pretty urls from example 1 to example 2 and back to example 1 agian. But I really don't know how to though and was wondering how I do this using PHP or do I need to use mod_rewrite in some way? Can someone explain this to me in laymans terms? And if there is a online tutorial on how to do this would help.

Example 1 - Here is my current url a element link and how it looks in the browser

http://www.example.com/members/1/posts/page.php?aid=123

Example 2 - But I want it to read the pages title.

http://www.example.com/members/1/posts/title-of-current-page/
HELP
  • 14,237
  • 22
  • 66
  • 100

1 Answers1

0

In pages table you can add a "url" column. Then insert formatted page title using like that code;

$text=str_replace(" ","-",trim($text)); 
$text=preg_replace("@[^A-Za-z0-9\-_]+@i","",$text); 
$text=ereg_replace(" +"," ",trim($text)); 
$text=ereg_replace("[-]+","-",$text); 
$text=ereg_replace("[_]+","_",$text);

On main page;

Simply, SELECT * FROM page_table WHERE url='$_GET["url"]'

miqbal
  • 2,213
  • 3
  • 27
  • 35
  • what if my page table does not have a url? – HELP Dec 24 '10 at 07:19
  • @HeLp You'll need to add one. Unless you're using a pk lookup you want to match by something in the database that you can reproduce programmatically; i.e. the url/slug that you generate by parsing the client's request has to match what you generated by parsing your page's title, or you won't be able to find any of your pages. A good sluggify function also makes it easy to sanitize that string before it goes near the database. – cbednarski Dec 24 '10 at 07:29