#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    94
    Rep Power
    6

    Put the result of a SQL query into a .htaccess file?


    Hi,

    I have just been trying to use mod_rewrite to create SEO friendly URLs. Very new to it.

    In an eCommerce store the product urls are:

    Code:
    site.com/products.php?id=1
    I want to use:

    Code:
    site.com/product-id-1s-title-from-inside-the-database
    You see ^ the SEO friendly URL is a string/record from the database, it's the title field for the product with an ID of 1.

    Can/how I use a SQL query inside the .htaccess file to make the writing of the .htaccess file automated? Or can you not do that, and my only option is to hardcode in the SEO friendly URLs by hand?

    There are over 1000 products you see.


    I'd appreciate any advice you can offer.

    Thanks very much.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,295
    Rep Power
    9400
    What you do is turn the friendly URL into the real URL using pattern matching.
    Code:
    /product-id-(\d+)
    Anything that looks like that gets rewritten to a different page. Say
    Code:
    products.php?id=$1
    Then products.php decides what to do from there according to $_GET["id"].


    You aren't creating a rule for every single URL. Just the different forms of them.

IMN logo majestic logo threadwatch logo seochat tools logo