adamjblakey Posted June 29, 2007 Share Posted June 29, 2007 Hi, What i am trying to achieve is convert all my urls to output a valid seo url. For example: If you go here: http://www.foundrecipes.com/recipes.php?type=all and select a category you would get something like http://www.foundrecipes.com/recipes.php?category=Automatic%20Bread%20Machine which is not a seo friendly url. What i would like is when a category is click the url would appear like so e.g. http://www.foundrecipes.com/recipes/category/Automatic-Bread-Machine.html i don't know if this can be done simply with a htaccess file or would i need to have something in the recipes.php page? Also this applies to when i click on a recipe, so for example if i click on the relevant recipe i wanted to see it would take me to e.g. http://www.foundrecipes.com/recipe-details.php?title=apple%20roquefort%20bread but i want this to output like e.g. http://www.foundrecipes.com/recipedetails/apple-roquefort-bread.html Thanks in advance for your help. Adam Quote Link to comment Share on other sites More sharing options...
hackerkts Posted June 29, 2007 Share Posted June 29, 2007 Hmm.. You will need to do it in both .htaccess and your recipes.php, as for the .htaccess, this is what I did for my <a href="http://howtoinstallscript.com/staff.html">Staff List</a>, you can see it when you clicked on the Staff name. .htaccess RewriteEngine on #start of mod rewrite RewriteBase // #if you have a folder, then put the folder name there RewriteRule ^recipes/category/(.*).html/ recipes.php?category=$1 #mod rewrite On your recipes.php you should contain this to help you change your dynamic url to static url, recipes.php (to display the static URLs) <?php # $row['category_title'] is your Category title $cat_url = strtr($row['category_title'], "éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ. ","eeeaeauoiaabcdefghijklmnopqrstuvwxyz--"); $cat_url = ereg_replace('[^a-zA-Z0-9_-]', '', $cat_url); # then to echo out it should be # echo '<a href="http://www.foundrecipes.com/recipes/category/'.$cat_url.'.html">'.$row['category_title'].'</a>'; ?> recipes.php (mysql query to find the category) <?php $query = "SELECT * FROM category"; #your query $result = mysql_query($query) or die("MySQL Error: ".mysql_error()); while ($row = mysql_fetch_assoc($result)) { $cat_url = strtr($row['category_title'], "éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ. ","eeeaeauoiaabcdefghijklmnopqrstuvwxyz--"); $cat_url = ereg_replace('[^a-zA-Z0-9_-]', '', $cat_url); if ($cat_url == ereg_replace('[^a-z0-9]', '', $_GET['category'])) { #echo out the result $search_result = 'found'; } } if ($search_result != 'found') { #echo 'Category not found!'; } ?> Hope this helps, all the best! Quote Link to comment Share on other sites More sharing options...
adamjblakey Posted June 29, 2007 Author Share Posted June 29, 2007 Thank you for your reply. This is what i have done so far but does not seem to work $selects = "SELECT * FROM recipes WHERE category = '$_GET[category]'"; $result = mysql_query($selects); $countrowssa = mysql_num_rows($result); if ($countrowssa < 1) { print "<b>There are currently no recipes with this criteria.</b>"; }else { while ($res = mysql_fetch_array($result)) { $resu[] = $res; } mysql_free_result($result); foreach ($resu AS $row) { $cat_url = strtr($row['title'], "éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ. ","eeeaeauoiaabcdefghijklmnopqrstuvwxyz--"); $cat_url = ereg_replace('[^a-zA-Z0-9_-]', '', $cat_url); echo "<li><a href='recipes/$cat_url.html'>".$row['title']."</a></li>"; } } Then i have added this to my htaccess file RewriteEngine On RewriteRule ^recipes/(.*)\.html$ recipe.php?category=$1 If i go to e.g. http://www.foundrecipes.com/recipes.php?category=Automatic%20Bread%20Machine it is changes the links to the next page but these links do not work. Is this setup correctly? Quote Link to comment Share on other sites More sharing options...
Hypnos Posted June 29, 2007 Share Posted June 29, 2007 It's always good to read error messages... "The requested URL /recipe.php was not found on this server." recipes.php, not recipe.php. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted June 29, 2007 Share Posted June 29, 2007 Check your .htaccess RewriteRule ^recipes/category/(.*).html/ recipes.php?category=$1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.