Confused About Mod_Rewrite

Discussion in 'Apache' started by Masterful, Mar 16, 2009.

  1. #1
    I have links on my site which look like this:

    products.php?prodid=11
    category.php?categid=9


    I have heard that I need this thing called mod_rewrite to write the URLs to something easier to remember and more search engine-friendly. I have been reading about mod_rewrite all day, and I am finding it hard to understand. Can anyone clarify, please, how to do the following?

    Change category.php?categid=9 to category/furniture

    And what about pagination? When I land on category.php?categid=9 and click to Page 2, the URL changes to category.php?categid=9&page=2. How do I implement mod_rewrite here?
     
    Masterful, Mar 16, 2009 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    I stay confused on this subject myself but am very slowly coming to terms with it.

    I currently believe that you have to have the rewrite functions in Apache and within the scripts to make maximum utilization of it. When you hover over a link it should show the rewritten URL there as well as in the browser window.

    The second part of your question the is another rewrite and should look like category/furniture/page/2/ or
    category/furniture/page2.html whichever you want.

    I hope I added something but I fear I only rambled on.
     
    Colbyt, Mar 16, 2009 IP
  3. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Thanks for the effort, Colbyt. :)

    I no longer need help with this matter, guys. I just noticed that there's a sticky dedicated to the subject. :eek:
     
    Masterful, Mar 16, 2009 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    For

    category.php?categid=9

    to match

    category/furniture

    you would need the script to know that furniture is ID 9. The easiest way to do it with no change to the script needed except changing the link part, is to keep the number in there, category/9/furniture

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^category/([^.]+)/([^.]+)$ category.php?categid=$1 [L]

    with the script knowing to add furniture to the link.
     
    Nintendo, Mar 16, 2009 IP
    Masterful likes this.
  5. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #5
    Thanks, Nintendo!

    One rep point for you. :)
     
    Masterful, Mar 17, 2009 IP