Apache rewrite

Discussion in 'Apache' started by ChocolateLover, Feb 5, 2009.

  1. #1
    I'm turning a static site into a dynamic site.

    This is an example of a url for a product page that exists at the moment
    www.example.com/pics/6.5W%20Sunlinq%20with%20iPod%20cable.php

    The new system has one products page which creates the product data dynamically, based on the product_id
    www.example.com/products.php?product_id=1
    The current product URL exists in the database

    I want to keep the existing URLs and use .htaccess to rewrite the products.php URL.

    I thought I could create and maintain a RewriteMap that would look something like this
    pics/6.5W%20Sunlinq%20with%20iPod%20cable.php products.php?product_id=1
    but I understand that you need access to the server configuration for this to work (is this correct?). I suspect that is not something that the hosts would allow(??). There could be up to 500 products.

    Given that only products pages have the prefix pics/ and that the URL exists in the database, would it be better to use .htaccess to look for the pics/ prefix, redirect to products.php with the current URL (e.g. pics/6.5W%20Sunlinq%20with%20iPod%20cable.php) as a parameter and then look for that value instead of the products_id to create the product page?

    I've never used mod_rewrite before so I'm looking for guidance.

    Any feedback would be gratefully received, thanks.
     
    ChocolateLover, Feb 5, 2009 IP
  2. kks_krishna

    kks_krishna Active Member

    Messages:
    1,495
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    80
    #2
    HI,

    You can use .htaccess if you are using the hosting also. They will by default enable the mod rewrite option for you.
     
    kks_krishna, Feb 6, 2009 IP