/    Sign up×
Community /Pin to ProfileBookmark

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:

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

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:

[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>[/CODE]

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

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Steelcity74authorNov 25.2014 — Dont know if this helps...but here is the code for the index.php which shows a preview of each blog post:

[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'], 0, 100);

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>[/CODE]


Thanks for the help
×

Success!

Help @Steelcity74 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...