.htaccess --Mod_redirect Help.

Discussion in 'PHP' started by clerk, Jul 13, 2007.

  1. #1
    I have a question and i cannot find the answer anywhere .

    I mean:

    Now Url is that:

    http://www.example.com/product.php?task=list&category_id=16

    http://www.example.com/product.php?task=show&id=295

    Want to change:

    http://www.example.com/product/category/16/ or http://www.example.com/product/list/category/16/

    http://www.example.com/product/show/295/

    i know that i can do that from the .htaccess file, but i've tryed and tryed and i just won a 500 Internal Server Error

    i hope some of you can help me :)

    thanks!!
     
    clerk, Jul 13, 2007 IP
  2. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok, think of the problem the other way around.

    Your public URL will be...
    http://www.example.com/product/category/16/

    But, internally, on your server, you want to treat it as if it were...
    http://www.example.com/product.php?category_id=16

    So, the code is...
    RewriteEngine on
    RewriteRule ^category/([0-9]+)/ product.php?category_id=$1

    The bit in brackets forms $1, and says look for *anything* followed by the word category, followed by a slash, followed by any number of digits. Take those digits and stuff them into $1. Then replace all of that with product.php?category_id= and add on the numbers you first thought of.

    Thinking of it like that, you can add in other parameters such as your "task" parameter quite easily. Another set of brackets will give you $2.
     
    ecentricNick, Jul 13, 2007 IP
  3. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #3
    it's called mod_rewrite not mod_redirect.

    Place this into your .htaccess

     
    legend2, Jul 13, 2007 IP
  4. Bishop81

    Bishop81 Peon

    Messages:
    757
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you have a problem with it still, then you may need to add the following:

    under the RewriteEngine on, place - RewriteBase /

    If you're still having trouble, then after the last RewriteURL, place [L]
     
    Bishop81, Jul 14, 2007 IP