I hope someone can help me. I have been working on this for several days and can not figure it out. I made a blog and I am trying to get SEO friendly URLs. I have tried the mod-rewrite and it seems to have no effect. is there something else that I have to do here? I am lost and cannot find much about it except for modifying the .htaccess file which i did.

the .htaccess rule i am using is:

RewriteEngine On
RewriteRule ^blog([a-zA-Z0-9]+)/$ viewposts.php?id=$1

Just to be clear, my blog is in the /blog/ directory. The .htaccess needs to go in the /blog directory...and not the website root? Is there something i am supposed to change in the PHP to get them. Here is my code for showing the blog post:

<?php include ('../includes/header.php');

require_once '../htmlpurifier/library/HTMLPurifier.auto.php'; ?>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta name="description" content="" />
  <meta name="keywords" content="" />
  <meta name="author" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
  <link rel="stylesheet" type="text/css" href="jquery.timepicker.css" />
  <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Merriweather:400,400italic,700italic" rel="stylesheet" type="text/css" />
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" />
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" />
  <link href="../styles/style.css" rel="stylesheet" type="text/css" />
  <link href="css/normalize.css" rel="stylesheet" type="text/css" />
  <script src="../includes/ckeditor/ckeditor.js"></script>
<script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript" src="http://s.sharethis.com/loader.js"></script>
  <title></title>
<style>
</style>
</head>

<body>
  <div class="container-fluid">
    <!--Begin whole container-->
    <!--Begin Nav Bar-->
    <?php include ('../includes/nav.php'); ?>
    <!--End Nav Bar--> 
    <div class="container">
      <!--Begin body container-->
      <div class="container">
        <h2 class="col-md-12">&nbsp;</h2>
      </div>
      <div class="col-md-9">
        <!--Begin Left Side-->
        <?php //connect to database
include '../connect.php';
$id = mysqli_real_escape_string($con,$_GET['id']);
//retreive the data
$sql = "SELECT postID, postTitle, postDesc, postCont, postDate FROM blog_posts WHERE postID=$id";
$result = mysqli_query($con,$sql);

if (mysqli_num_rows($result) > 0){
                // output data of each row
                while ($row = mysqli_fetch_assoc($result))
                {
                                $purifier = new HTMLPurifier();
                                $clean_html = $purifier->purify($row['postCont']);
                                echo '<div id="start" class="container content">';
                                echo '<div class="row">';
                                echo '<div class="col-md-8">';
                                echo '<h1 class="post-head">' . ucwords($row['postTitle']) . '</h1>';
                                echo '<div class="post-date"><i class="fa fa-calendar"></i> Posted on ' . date('jS M Y H:i:s',
                                                strtotime($row['postDate'])) . ' | By Steven Gray</div>'; ?>
              <hr>
              <?php                              echo '<p>' . $clean_html . '</p>';
                                echo '</div>';
                                echo '</div>';

                                echo '</div>';
                }
} ?> 
    <div class="row">
  <div class="col-lg-8 col-sm-8 col-xs-12"> 
  <h4 id="addComment">
  <?php include '../connect.php';
$postid = $_GET['id'];
$total = mysqli_query($con,"SELECT COUNT(post_id) FROM blog_comments where post_id=$postid");
$rowss = mysqli_fetch_row($total);
$num = $rowss[0]; ?><kbd><?php echo $num ?> comment(s) to this post.</kbd></h4>
     <hr />   
    <?php include '../connect.php';
$q = "SELECT blog_comments.comment_id, blog_comments.post_id,blog_comments.user_id,blog_comments.comments, blog_comments.comDate, users.user_name
    FROM blog_comments INNER JOIN users on users.user_id=blog_comments.user_id
    WHERE blog_comments.post_id=$id";
$r = mysqli_query($con,$q);
if (mysqli_num_rows($r) > 0)
{
                while ($rows = mysqli_fetch_assoc($r))
                {
                                $user = $rows['user_name'];
                                $cdate = substr($rows['comDate'],0,11);
                                $c = $rows['comments']; ?>           

    <ul class="media-list comments">
      <li class="media">
        <a class="pull-left" href="../profile.php?id=<?php echo $rows['user_id'] ?>">
        <img class="media-object img-circle img-thumbnail" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=100" width="44" alt="member profile pic"/></a>
        <div class="media-body">
          <h5 class="media-heading pull-left"><a href="../profile.php?id=<?php echo $rows['user_id'] ?>"><strong><?php echo $user ?></strong></a> on <strong><em><?php echo $cdate ?></em></strong> said:</h5>
          <br class="clearfix"/>
          <?php echo $c ?>
        </div>
      </li>
      <hr />     
    <?php                }
} else
{
                echo '<div>Why don\'t you be the first?</div>';
                echo '<div>&nbsp;</div>';
} ?> 
   </ul>
  </div>  
</div>

        <?php //Show the reply box
if (!$_SESSION['signed_in'])
{
                //IF not logged in show this
 ?>
                <p>
                You must be <a href="../forum/signin.php">signed in</a> to post a comment. You can also <a href="../forum/signup.php">sign up</a> for an account.
                </p>
                <br />
             <?php }
//if logged in...show the comment box
else
{ ?>

        <div class="well">
          <h4><i class="fa fa-paper-plane-o"></i> Leave a Comment:</h4>

          <form class="form" action="" method="post">
            <div class="form-group">
              <textarea id="comment" name="comment"class="form-control" rows="3"></textarea>
            </div><button type="submit" name="submit" id="submit" class="btn btn-primary"><i class="fa fa-reply"></i> Submit</button>
          </form>
        </div>

        <?php }
if (isset($_POST['submit']))
{
                $comment = mysqli_real_escape_string($con,$_POST['comment']);
                $poster = mysqli_real_escape_string($con,$_SESSION['user_id']);
                $post_id = mysqli_real_escape_string($con,$_GET['id']);
                $comDate = date("Y:m:d H:i:s");

                mysqli_query($con,"SELECT * FROM blog_comments");
                $commentsql = "INSERT INTO blog_comments (comment_id, user_id, post_id, comments, comDate)
    VALUES ('', '$poster', '$post_id', '$comment', '$comDate')";

                if (mysqli_query($con,$commentsql))
                {
                                echo "New comment successfully submitted";
                } else
                {
                                echo "Error: " . $commentsql . "<br>" . mysqli_error($con);
                }
} ?>
      </div><!--End Left Side-->

      <?php include ('../includes/sidebar.php');
mysqli_close($con); ?>
    </div><!--End body container-->
    <hr />
    <?php echo $footer ?>
  </div><!--End whole container--> 

  <script>
// Replace the <textarea id="reply-content"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'comment',{

});//extraPlugins: 'codesnippet';
  </script>
  <script type="text/javascript">stLight.options({publisher: "143366f8-0be4-4b57-ac9b-b244ac0028a7", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>
<script>
var options={ "publisher": "143366f8-0be4-4b57-ac9b-b244ac0028a7", "position": "left", "ad": { "visible": false, "openDelay": 5, "closeDelay": 0}, "chicklets": { "items": ["facebook", "twitter", "linkedin", "pinterest", "email"]}};
var st_hover_widget = new sharethis.widgets.hoverbuttons(options);
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script> <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js">
</script> <script type="text/javascript" src="jquery.timepicker.js">
</script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js">
</script>
</body>
</html>

Im not sure what i am missing here. Can someone help me please?

my blog currently outputs like this:
viewposts.php?id=5

I want it to be something like:
viewposts.php/blog_title_here

Thanks a lot

that does not work....

I typed in www.example.com/blog/32 which is supposed to redirect to www.example.com/blog/viewposts.php?id=32 and i get a 404 error.

not good with these but should that not be

    RewriteRule ^blog/([a-zA-Z0-9]+)$ /viewposts.php?id=$1 [L]

Maybe i am missing something here.....i have tried both versions...neither work. The page i am trying to fix up is:

http://www.tinkerplayground.com/blog

if you click any link on a blog title....thats what i am trying to change..so it reads viewposts.php/32....and not viewposts.php?id=32

I manually typed in both http://www.tinkerplayground.com/blog/32 and http://www.tinkerplayground.com/blog/viewposts.php/32 and neither work

the .htaccess is in the blog root which is /blog/

what am i missing here? my site is hosted with host gator and they have mod-rewrite enabled.

RewriteEngine On
RewriteRule ^blog/([^/]*)$ /?id=$1 [L] then i think