i want to rewrite URL like this

Discussion in 'PHP' started by great_friend, Oct 11, 2008.

  1. #1
    Hello Guys,
    i have This URL
    http://website.com/ringtones.php?id=12&name=funny-ringtones

    I want URL like this
    http://website.com/12-funny-ringtones.html

    i have done this work with the help of .htaccess file like this
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*)-(.*).html ringtones.php?id=$1&name=$2

    but when i add another url in same condition and same .htaccess file like this
    RewriteRule (.*)-(.*).html games.php?id=$1&name=$2

    then both are not working properly and showing php errors in webpage

    Anyone help me that how can i do this ?
    please reply me
    Thanks
     
    great_friend, Oct 11, 2008 IP
  2. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You are using same url for both conditions... (.*)-(.*).html, will it go to Games section or Ringtones section?

    You may try giving them both a directory like:
    
    RewriteRule ringtones/(.*)-(.*).html ringtones.php?id=$1&name=$2
    RewriteRule games/(.*)-(.*).html games.php?id=$1&name=$2
    Code (markup):
     
    mehdi, Oct 11, 2008 IP
  3. great_friend

    great_friend Active Member

    Messages:
    377
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Hello Mehdi,
    Thanks for your reply but i don't want to fixed any parameter like ringtones or games
    i want direct link without any fixed parameter
    it is possible or not ?
    please reply me

    Thanks
     
    great_friend, Oct 11, 2008 IP
  4. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
  5. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry, i dont understand wht u are talking about but if you want Fixed 'ringtones' and 'games' to be variable then try this:

    RewriteRule (.*)-(.*)-(.*).html $1.php?id=$2&name=$3
    Code (markup):
    It means that if you enter
    games-01-wohoo.html will be actually games.php?id=01&name=wohoo

    and if you enter
    ringtones-01-funny+ringtone.html , will be actually ringtones.php?id=01&name=funny+ringtone

    hope this is what you are looking for.
    Thanks
     
    mehdi, Oct 11, 2008 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That leaves a huge gap for errors. It would make more sense to have a single file process all of them, and use code in the script to work out the category based on the $_GET['name'] that you send to the script
     
    JAY6390, Oct 12, 2008 IP