Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    9
    Rep Power
    0

    SEO Dynamic URL's - Help Please


    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:

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


    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 Code:
    <?php include ('../includes/header.php');//header includes session();

    require_once '../htmlpurifier/library/HTMLPurifier.auto.php'?>//this is to sanitize the output
    <!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
  2. #2
  3. Anemic Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,808
    Rep Power
    9432
    For one, your URL rewriting will only work with things like "/blog5". Try that - does it work? Or at least does it work the same way that /viewposts.php?id=5 does?

    URL rewriting can only rearrange parts of it. Can't add information that isn't there. If you want to support "/blog_title_here" then your script needs to support finding a blog post according to "title_here", like /viewposts.php?title=title_here.
    Then
    Code:
    RewriteEngine On
    RewriteRule ^blog_([a-zA-Z0-9]+)/$ viewposts.php?title=$1
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    9
    Rep Power
    0
    Originally Posted by requinix
    UIf you want to support "/blog_title_here" then your script needs to support finding a blog post according to "title_here", like /viewposts.php?title=title_here.
    Then
    Code:
    RewriteEngine On
    RewriteRule ^blog_([a-zA-Z0-9]+)/$ viewposts.php?title=$1
    Can you help me with that.....?
  6. #4
  7. Anemic Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,808
    Rep Power
    9432
    Were you the one who wrote the code for that file initially? If not, is the original developer still around?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    9
    Rep Power
    0
    Originally Posted by requinix
    Were you the one who wrote the code for that file initially? If not, is the original developer still around?
    I wrote the code but I have been going crazy trying to figure this out. I wanted to make my own blog and not use a tray made one or framework. Perhaps I should post the index page for you to see as well?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    9
    Rep Power
    0
    Here is my index.php which links to viewposts.php:

    PHP Code:
    <?php include('../includes/header.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 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="http://fonts.googleapis.com/css?family=Oswald:regular,700" rel="stylesheet" type="text/css">
      <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,700|Merriweather:400,400italic,700italic" rel="stylesheet" type="text/css" />

    <style>
    .blog_title, h1 {
     color: #5bc0de;
     @font-face {
      font-family: 'Oswald';
      font-style: normal;
      font-weight: 700;
      src: local('Oswald Bold'), local('Oswald-Bold'), url(http://fonts.gstatic.com/s/oswald/v10/bH7276GfdCjMjApa_dkG6T8E0i7KZn-EPnyo3HZu7kw.woff) format('woff');
     margin: 0;
     text-shadow: #aaa 5px 5px 5px;
    }

    </style>

      <title></title>
    </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-->
          <header class="section-header">
            
    <h1 class="hidden-lg hidden-md"><?php echo $blogtitle?></h1>

            <!-- Carousel
    ================================================== -->
    <div id="myCarousel" class="carousel slide">  
      <div class="carousel-inner">
        <div class="item active">
          <img class="hidden-xs hidden-sm" src="../images/smoke.jpg" class="img-responsive">
          <div class="container">
            <div class="carousel-caption">
              <h1><?php echo $blogtitle?></h1>
              <p>What's happening around here.</p>
              </div>
          </div>
        </div>    
      </div>
    </div>
    <div>&nbsp;</div>
    <!-- /.carousel -->
            </header>
          <div class="col-md-9">
            <!--Begin Left Side-->
            <?php
            
    //connect to database
            
    include '../connect.php';
            
    //retreive the data
            
    $sql "SELECT postID, postTitle, postDesc, postCont, postDate FROM blog_posts ORDER by postDate Desc";
            
    //if successfull-display confirmation
            
    $result=mysqli_query($con$sql);

            if (
    mysqli_num_rows($result) > 0) {
                
    // output data of each row
                
    while($row mysqli_fetch_assoc($result)) {
                  
    $subject=   substr($row['postDesc'], 0100);
                  

                echo 
    '<div id="start" class="container content">';
                echo 
    '<div class="row">';
                  echo 
    '<div class="col-md-8">';
                    echo 
    '<article class="clearfix">';
                     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>';
                      echo 
    '<h2><a href="viewposts.php?id=' $row['postID'] . '">' ucwords($row['postTitle']) . '</a></h2>';
                      echo 
    '<p>' $subject ' &raquo;</p><p><a class="btn btn-info" href="viewposts.php?id=' $row['postID'] . '">Read More</a></p>';
                    echo 
    '</article>';
                  echo 
    '</div>';
                echo 
    '</div>';
              echo 
    '</div>';
            }
            }
            
    ?>
          </div><!--End Left Side-->
          <?php include('../includes/sidebar.php'); ?>
        </div><!--End body container-->
        <hr>
        <?php echo $footer ?>
      </div><!--End whole container-->
    <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>
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    9
    Rep Power
    0
    Here is the website that is giving me the problem:

    301 Moved Permanently

    Thanks a lot
  14. #8
  15. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    I don't know or think that that will help.

    If you were to use Req's advice and translate the URL

    http://www.example.com/my_blog

    into

    http://www.example.com/viewposts.php?title=my_blog

    Then viewposts.php would need to read the $_GET['title'] and query your database to find the article that has the saved URL of "my_blog" then return that to the browser.
    Last edited by badger_fruit; November 25th, 2014 at 04:09 PM.
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  16. #9
  17. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    Removed
    Last edited by badger_fruit; November 26th, 2014 at 04:32 AM. Reason: DUPLICATE POST REMOVED
  18. #10
  19. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,200
    Rep Power
    493
    Removed
    Last edited by badger_fruit; November 26th, 2014 at 04:32 AM. Reason: DUPLICATE POST REMOVED
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    9
    Rep Power
    0
    OK....i took my postTitle column and made it into a string with "-"'s using this:

    //Unwanted: {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( )
    $postSlug = preg_replace("/[^a-z0-9_\s-]/", "", $row['postTitle']);
    //Clean multiple dashes or whitespaces
    $postSlug = preg_replace("/[\s-]+/", " ", $row['postTitle']);
    //Convert whitespaces and underscore to dash
    $postSlug = preg_replace("/[\s_]/", "_", $row['postTitle']);

    and saved this in a new column in my blog_posts table under the name of "idname"

    Then i made my link look like this:

    <a class="btn btn-info" href="viewposts.php?id=' . $postSlug . '">Read More</a>

    on viewposts.php it says this says this:

    $id = mysqli_real_escape_string($con,$_GET['id']);

    and my sql is this:

    $sql = "SELECT postID, idname, postTitle, postDesc, postCont, postDate FROM blog_posts WHERE idname=$id";

    and it spits out this error:

    Error: Unknown column 'Sample_Slug_Title' in 'where clause' - See more at: 301 Moved Permanently

    Any Suggestions?
  22. #12
  23. Anemic Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,808
    Rep Power
    9432
    $id is a string (you should rename all those things - maybe "idname"? The variable and the key in $_GET) so it needs to use quotes in the query.
    PHP Code:
    $sql "SELECT postID, idname, postTitle, postDesc, postCont, postDate FROM blog_posts WHERE idname='$idname'"
    Then
    Code:
    # /blog/.htaccess
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* viewposts.php?idname=$0
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    9
    Rep Power
    0
    you are a genius.....That worked....thanks so much....now the question i have is...how do i display it?

    If i physically take out the ?idname=Zombies_have_taken_over_VCU_Medical_Center

    and change it to this: /blog/Zombies_have_taken_over_VCU_Medical_Center

    it works with everything you have said.....but how do i make it show /blog/Zombies_have_taken_over_VCU_Medical_Center automatically instead of me having to delete it in the address bar...in other words...automatic when i click the link in index.php...it automatically shows the right way in the address bar

    thank you soooooo much
  26. #14
  27. Anemic Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,808
    Rep Power
    9432
    Your code is the one making the links
    PHP Code:
                      echo '<h2><a href="viewposts.php?id=' $row['postID'] . '">' ucwords($row['postTitle']) . '</a></h2>'
                      echo 
    '<p>' $subject ' &raquo;</p><p><a class="btn btn-info" href="viewposts.php?id=' $row['postID'] . '">Read More</a></p>'
    so change that.
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    9
    Rep Power
    0
    Duh....sorry...brain fart...it is all working now...thanks so much for your help
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo