Converting dynami php links to static links

Discussion in 'PHP' started by leony, Jan 18, 2008.

  1. #1
    Hello,

    I have got a website which is PHP and Mysql driven. And the address of a particular product goes like: product.php?parent_id=5&product_id=10....

    If the product name is let's say: ipod nano 1 gb, how can I make the link address look like: product.php/ipod-nano-1-gb (search engine friendly)

    or preferable can I get rid of .php or .html in the address completely?
     
    leony, Jan 18, 2008 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    You would need to modify the script to send titles of the products rather then numeric id's. Then you would need to modrewrite the site.
     
    HuggyStudios, Jan 18, 2008 IP
  3. leony

    leony Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for the reply. Can you explain more in detail? If I send the title, there will be %20 in the link as there is space which I do not want. I do not know about modrewrite though.
     
    leony, Jan 18, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    RewriteEngine On
    RewriteRule ^product/([\w-]+)$ product.php?product_title=$1
    
    Code (markup):
    With this, you'd have to modify your PHP script to fetch the items by title. Like product.php?product_title=ipod-nano-1-gb

    And you have to modify the script that generates these links to replace spaces with dashes.

    
    $title = preg_replace('~[^\w-]+~', '-', $title);
    
    PHP:
     
    nico_swd, Jan 18, 2008 IP
  5. lv211

    lv211 Peon

    Messages:
    168
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    lv211, Jan 18, 2008 IP
  6. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #6
    Yes ^^

    Just use urlencode($var) on the titles being sent, that way it will remove all of the %20 and replace it with a +
     
    HuggyStudios, Jan 18, 2008 IP