Web Services
  Home arrow Web Services arrow Page 6 - Make Dynamic URLs Search Engine Friendly
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WEB SERVICES

Make Dynamic URLs Search Engine Friendly
By: Peter Lavin
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 52
    2004-03-01

    Table of Contents:
  • Make Dynamic URLs Search Engine Friendly
  • Check Your Server
  • Create an .htaccess File
  • Upload .htaccess to Your Server
  • Test the Results
  • Modifying Your Code
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Make Dynamic URLs Search Engine Friendly - Modifying Your Code


    (Page 6 of 7 )

    Now that you’ve tested your URL and it works, modifying your code is all that remains to be done. Every instance of a dynamically-created URL must be revised. Just to clarify, in our example that would be all URLs that invoke the page main.php using a query string with two parameters, the first named category and the second named subject. Any other dynamic URLs that do not match this pattern will have to have their own separate rewrite rule. But let’s keep it simple and look at a code example, again referring to our sample URL.

    Original Code

    Assume that our database has been opened and the result set of a query has been returned into the variable $rs. Iterating through this result set using a while loop creates the dynamic URLs. This is done with the following code:

    <?php
    while($row = @ mysql_fetch_array($rs)){
    $category = $row["category"];
    $category = URLencode(htmlentities($category,ENT_QUOTES));
    $subject= $row["subject"];
    $subject = URLencode(htmlentities($subject,ENT_QUOTES));
    /*format for following HTML result
    http://www.mysite.com/main.php?category=books&subject=biography
    */
    echo "<a href=\"http://www.mysite.com/main.php?
    category=$category&subject=$subject\">";
    echo "$row[description]</a><br>\n";
    }
    ?>

    The fields category and subject are self-explanatory. description is simply the text that will appear as the clickable hyperlink. You can see in this example how a query string with two parameters has been created. The first parameter is separated from the page itself by a “?” and the second by an “&”. This is the line of code that will need modification.

    Revised Code

    <?php
    while($row = @ mysql_fetch_array($rs){
    $category = $row["category"];
    $category = URLencode(htmlentities($category,ENT_QUOTES));
    $subject= $row["subject"];
    $subject = URLencode(htmlentities($subject,ENT_QUOTES));
    /*format for the URL rewrite is as follows
    http://www.mysite.com/type$category-$subject.htm
    */
    echo "<a href=\"http://www.mysite.com/type$
    category-$subject.htm\">";
    echo "$row[description]</a><br>\n"; 
    }
    ?>

    Notice that a comment showing the format we are aiming for has been inserted into the code. This is the text that was saved in the file format.txt. It will serve as a handy reference so that mistakes are avoided. You can see that all that has been changed is the one line that actually creates the query string.

    More Web Services Articles
    More By Peter Lavin


       · i tried everything but i still couldnt get it.look my site is...
       · I have implemented the it as described above. However it is not displaying data...
       · I have implemented the it as described above. However it is not displaying data...
     

    WEB SERVICES ARTICLES

    - Safety, Idempotence, and the Resource-Orient...
    - The Resource-Oriented Architecture in Action
    - Features of the Resource-Oriented Architectu...
    - The Resource-Oriented Architecture
    - Getting Started with Flex
    - Automated Billing and Faxing for the Web
    - An Introduction to Web Services
    - The Foundations of Web Services: From Novice...
    - Web Services Reengineering: Finishing Touches
    - Fault Handling with Web Services
    - Flow and Web Services
    - Process Lifecycles and Web Services
    - Business Processes and Web Services
    - Orchestrating Web Services
    - Notifications and Resources in the WS-Resour...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek