gc40 Posted December 1, 2007 Share Posted December 1, 2007 Currently, I am using .htaccess rewrite to change some of the names of my URLs. However, I want to take it to another level. Currently, here is what I have: RewriteEngine On RewriteRule ^newsarticle/page/([0-9]+)/?$ newsarticle.php?id=$1 So if my news article was located at: http://www.mydomain.com/newsarticles.php?id=3, it will now be http://www.mydomain.com/newsarticles/page/3 However, I want it a little different. Rather than ending in with the ID number, I want the URL to have the title. If the news article title is Cool News Article, then I want the URL to be http://www.mydomain.com/newsarticles/Cool-News-Article Does anyone know what I would have to do to accomplish this task? p.s. All news articles are pulled from a database and the title is stored in the field called `title`. Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted December 1, 2007 Share Posted December 1, 2007 In your newsarticles.php file, instead of searching your DB for an ID number (from $_GET['id']), have it search for the title: Example: instead of <?php $id = $_GET['id']; mysql_query("SELECT * FROM articles WHERE id='$id'"); ?> Do something like: <?php $title = substr("-"," ",$_GET['id']); // this changes Cool-News-Article into Cool News Article mysql_query("SELECT * FROM articles WHERE title='$title'"); ?> Get what Im saying? Quote Link to comment Share on other sites More sharing options...
gc40 Posted December 1, 2007 Author Share Posted December 1, 2007 I am lost still. Here is my code for the actual page that will display the article: <?php $current = 'training'; $fullpage = 'yes'; include("./class/config.php"); $id=$_REQUEST['id']; $start=$_REQUEST['start']; $sqlcontent="Select * from training where Training_ID='$id' LIMIT 1"; //$resprop=mysql_query($sqlprop,$db); $rescontent=mysql_query($sqlcontent); $onecontent=mysql_fetch_object($rescontent); $row = mysql_fetch_array($rescontent); ?> <?php include('header_top.php');?> <title><?php print ($onecontent->Training_Title); ?></title> <meta name="title" content="<?php print ($onecontent->Training_Title); ?>" /> <meta name="keywords" content="<?php print ($onecontent->Training_Meta_Keywords); ?>" /> <meta name="description" content="<?php print ($onecontent->Training_Meta_Description); ?>" /> <?php include('header.php'); echo "<h1>".$onecontent->Training_Title."</h1>"; echo "<p>".$onecontent->Training_Body."</p>"; echo "<p><a href='javascript:history.go(-1)'>» Back</a></p>"; include('footer.php'); ?> Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted December 1, 2007 Share Posted December 1, 2007 Change to something like: <?php $current = 'training'; $fullpage = 'yes'; include("./class/config.php"); // i never use $_REQUEST by the way $title = substr("-"," ",$_GET['id']); // get the title and replace - with $start=$_REQUEST['start']; $sqlcontent="Select * from training where Training_Title='$title' LIMIT 1"; // you will need to edit your column name if i dont have it right //$resprop=mysql_query($sqlprop,$db); $rescontent=mysql_query($sqlcontent); $onecontent=mysql_fetch_object($rescontent); $row = mysql_fetch_array($rescontent); ?> <?php include('header_top.php');?> <title><?php print ($onecontent->Training_Title); ?></title> <meta name="title" content="<?php print ($onecontent->Training_Title); ?>" /> <meta name="keywords" content="<?php print ($onecontent->Training_Meta_Keywords); ?>" /> <meta name="description" content="<?php print ($onecontent->Training_Meta_Description); ?>" /> <?php include('header.php'); echo "<h1>".$onecontent->Training_Title."</h1>"; echo "<p>".$onecontent->Training_Body."</p>"; echo "<p><a href='javascript:history.go(-1)'>» Back</a></p>"; include('footer.php'); ?> Now just edit your .htaccess and you should be good to go Quote Link to comment Share on other sites More sharing options...
gc40 Posted December 1, 2007 Author Share Posted December 1, 2007 Hey bud, thanks for trying to help, but it isn't working. I can't get it figured out!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.