Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
04-07-2013, 12:51 PM #1
- Join Date
- Apr 2013
- Thanked 0 Times in 0 Posts
How to add page title in url in a dynamic site
I have a website called gapagap.com that is developed using php.
What I want to know is how can I change my url from this pattern:
As you can see that basically I want the page title to appear at the end of url and not the post sequence number.
04-07-2013, 03:49 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,668 Times in 2,637 Posts
Is the 54 a numeric id associated with the title? If so, you don't need to change a lot.
This is currently using a mod_rewrite to convert the url into one that is appropriate for the script in question. It's highly probable that you do not have site.com/gag/xx/index.[php|html|whatever] where xx is an id, and more likely that you have a site.com/gag.php where xx is then provided as querystring gag.php?id=54 for example. Assuming that's the case, and also assuming that id is always numeric, and also assuming that the rewrite rules allow it through, you can use the current rules and modify the underlying code.
Somewhere you will have something along the lines of:
$id = $_GET['id'];
// query where ID = $id (minding SQL security as well)
SELECT id, title, joke FROM gag WHERE id = $id. Now all you need to do is detect if it's numeric, and if it is, use the id, otherwise use the title.
$sQry = "SELECT id, title, joke FROM gag WHERE id = " . (int)$_GET['id'];
$title = escape($_GET['id']);
$sQry = "SELECT id, title, joke FROM gag WHERE title = '$title'";
header('HTTP/1.1 420 Enhance Your Calm');