0

I am able to create a unique URL http://site.com/pod.php?id=20

I have had 404 errors when trying different methods through php and htaccess to rewrite the URLs.

I have different fields in the database which I would like to use in order to construct the URL and make it SEO friendly. These fields would be name, location and category. The URL should be like this http://site.com/name/location

Really what I am asking is how do I accomplish this? Examples would be fantastic.

Files I use below:

part of content.php

    while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "<div class=\"pods\">";
echo "<a href=\"/pod.php?id={$row['id']}\">";
echo "<div class=\"podHeading\">";  
echo "{$row['heading']}</a> <br> ";
echo "</div>";
echo "<div class=\"podImage\">";    
echo "<img src=\"images/{$row['imageName']}\">";
echo "</div>";

$string = "{$row['text']}";
if(strlen(htmlspecialchars_decode($string)) > 100) {
echo substr(htmlspecialchars_decode($string), 0, 100).'...'.$hyperlink;}
else {
echo htmlspecialchars_decode($string);
}

pod.php:

<?php
$connect = mysql_connect('x', 'x', 'x');
$select_db = mysql_select_db('x');

$id = mysql_real_escape_string($_GET['id']);
$query = 'SELECT * FROM podContent WHERE id = '.$id.' LIMIT 1';
$result = mysql_query($query);
$row = mysql_fetch_array($result);

// Echo page content
echo "<div class=\"podPageContainer\">";
echo "<div class=\"podPageContent\">";
echo "<div class=\"podPageHeading\">";
echo $row['heading'];
echo "</div>\n";
echo "<br/>";
echo $row['text'];
echo "</div>\n"; 
echo "</div>\n";
echo "<div class=\"pageSidebar\">";
include('ads/sidebarAds.php');
echo "</div>\n";
?>

.htaccess

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.site.com/$1 [R=301,L]  

Options +FollowSymlinks
RewriteEngine On

Any help is greatly appreciated, Thank you!

AyeTry
  • 75
  • 3
  • 12
  • 1
    why are you changing the original working url? –  Mar 05 '13 at 20:14
  • Sorry, I may not have made it clear that I want to change URL so that name/location... instead of pod.php?id=1 and this should be a more user friendly and SEO friendly, is it not? – AyeTry Mar 05 '13 at 20:18
  • no its not, its a common misconception, its the value of the content not the url that determine your search engine ranking. From google themselves: http://googlewebmastercentral.blogspot.co.nz/2008/09/dynamic-urls-vs-static-urls.html –  Mar 05 '13 at 20:20
  • As long as the name and location is enough to identify an unique.. pod, then it should be easy enough to do – kjetilh Mar 05 '13 at 20:21
  • @Dagon Well put it this way I would rather a nicer url rather than pod.php?id=1, would you be able to assist me? – AyeTry Mar 05 '13 at 20:24
  • nope, i don't like pointless tasks. You would get more value spending the time on content. –  Mar 05 '13 at 20:26
  • @AyeTry how about something like **http://site.com/pod/20**? – kjetilh Mar 05 '13 at 20:26

1 Answers1

0

what you need is the htaccess to that for you

change ur rewriteRule to this

^[a-zA-Z0-9-_]/[a-zA-Z0-9-_]$ http://www.site.com/index.php?name=$1&location=$2

so you can get the name and location through $_Get method