i want to rewrite URL like this

Discussion in 'Apache' 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. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    MAYBE, because of conflict?
    RewriteRule (.*)-(.*).html ringtones.php?id=$1&name=$2
    RewriteRule (.*)-(.*).html games.php?id=$1&name=$2
    Code (markup):
    that means 12-funny-ringtones.htm can be ringtones.php?id=12&name=funny-ringtones OR games.php?id=12&name=funny-ringtones.

    If that's the problem, then you can try to add a prefix to the new url.
    example:
    RewriteRule ringtones-(.*)-(.*).html ringtones.php?id=$1&name=$2
    RewriteRule games-(.*)-(.*).html games.php?id=$1&name=$2
    Code (markup):
     
    djzmo, Oct 11, 2008 IP
  3. great_friend

    great_friend Active Member

    Messages:
    377
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #3
    great_friend, Oct 11, 2008 IP
  4. djzmo

    djzmo Active Member

    Messages:
    165
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Yes. But logically, the code you used in the htaccess is invalid.
    IMO, that's the reason.

    You have to use two different representation, or the webserver will get confused on what the url will be rewritten to.

    It's something like this:
    - Someone visited http://www.website.com/12-funny-ringtones.html
    RewriteRule (.*)-(.*).html ringtones.php?id=$1&name=$2
    Code (markup):
    - .htaccess told the webserver to rewrite the url from http://www.website.com/12-funny-ringtones.html to http://www.website.com/ringtones.php?id=12&name=funny-ringtones.
    RewriteRule (.*)-(.*).html games.php?id=$1&name=$2
    Code (markup):
    - .htaccess told the webserver AGAIN to rewrite the url from http://www.website.com/12-funny-ringtones.html to http://www.website.com/games.php?id=12&name=funny-ringtones.

    So you will have to change the (.*)-(.*).html and give it an unique name. For example, ringtones-(.*)-(.*).html for ringtones.php?id=&name= and games-(.*)-(.*).html for games.php?id=&name=.
     
    djzmo, Oct 11, 2008 IP
  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