TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   SEO Friendly URL, Fetched from Databse Category Id etc.. (http://www.talkphp.com/absolute-beginners/4773-search-engine-optimization-friendly-url-fetched-databse-category-id-etc.html)

woowoo 07-23-2009 07:50 PM

SEO Friendly URL, Fetched from Databse Category Id etc..
 
Ok Im an aboslute noob and dont even know if my title is on target for what I want to do.

I have a script here that creates categories etc, it's all PHP and something like ZenCart, OScommerce etc but with it I want to know how to turn it around to have SEO friendly URL's.

WhenI enter a category or product Id in the back office it I assume it stores them in the ?databse? so in aassuming that they are stored in there as category1 and product 2 and so forth.

This is the code used to call the category ID to the page.

Code:

if(!empty($_GET[CategoryID]))
{
        $query[] = " ItemCategory = '$_GET[CategoryID]' ";
}

Here is the code on the admin page that is used to enter the category ID to the database.

Code:

<?
require_once("../conn.php");
require_once("access.php");
require_once("../includes.php");
require_once("AdminNavigation.php");

if(isset($_POST[s1]))
{
        if(!empty($_POST[categoryname]))
        {
                $q1 = "insert into dd_categories set
                                CategoryName = '$_POST[categoryname]' ";
                $r1 = mysql_query($q1);

                if(mysql_error())
                {
                        $error = "<span class=BlackLink>The category name <font color=black>$_POST[categoryname]</font> already exist!</span>";
                }
        }
        else
        {
                $error = "<span class=BlackLink>Enter the New Category name, please!</span>";
        }
}

?>

<br>
<center>

<span class=BlackLink>Add a new category</span>
<br><br>

<form method=post>
<table align=center width=350>
<caption align=center><?=$error?></caption>
<tr>
        <td align=right>New Category name:</td>
        <td><input type=text name=categoryname size=20></td>
        <td><input type=submit name=s1 value="Add"></td>
</tr>

</table>
</form>

<?

$q1 = "select * from dd_categories order by CategoryName";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
        echo "<br>";

        echo "<table align=center width=300 cellspacing=0><caption align=center><span class=BlackLink>Categories List:</span></caption>\n<tr class=TableHead>\n\t<td>Categories</td>\n\t<td align=center>Action</td>\n</tr>\n\n";
       
        $col = "white";

        while($a1 = mysql_fetch_array($r1))
        {
                if($col == "white")
                {
                        $col = "dddddd";
                }
                else
                {
                        $col = "white";
                }

                echo "<tr bgcolor=$col>\n\t<td align=left>$a1[CategoryName]</td>\n\t<td width=100 align=center><a class=GreenLink href=\"EditCategory.php?CategoryID=$a1[CategoryID]\">edit</a> | <a class=BlackLink href=\"DeleteCategory.php?CategoryID=$a1[CategoryID]\" onclick=\"return cdel('$a1[CategoryName] category');\">delete</a></td>\n</tr>\n\n";
        }

        echo "</table>";
}
?>

My ultimate goal is to get the url of category and on the product pages to be the name that I give the product or category.

I chose this question because ultimately it is going to help me understand the admin panel, moving stuff to a databse and linking together code.

I look forward to a response.

Thank you everyone.

jcorradino 07-26-2009 03:07 AM

ok, it seems that you are getting something like yourwebsitehere.com/index.php?category=fu&product=bar, but you would rather have yourwebsitehere.com/fu/bar/.

The easy way to do this would be through the following code in a .htaccess in your main www directory.

Code:

RewriteEngine on
Options +FollowSymLinks
RewriteRule ^(.+)/(.+)/ index.php?category=$1&product=$2 [L,NC,QSA]
RewriteRule ^(.+)/ index.php?category=$1 [L,NC,QSA]

If there is more than that, just keep adding (.+)/'s up to 9.

This will show the user a nice SEO friendly, readable URL, while passing the data the webapp needs to function.

www.website.com/electronics/laptop2/ = http://www.website.com/index.php?cat...roduct=laptop2

Hope this helped :)

EDIT: Then again, I just realized that if the app was not built by you, you will need to rewrite the linking structure for the site. As all links will still point to the nasty link. Most CMS software supports seo friendly linking, either out of the box or through a plugin.


All times are GMT. The time now is 03:41 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0