mod_rewrite :What I am doing wrong?

Discussion in 'Apache' started by rahman15, Mar 14, 2006.

  1. #1
    I am trying to use mod_rewrite for my urls. Here is my .htaccess file.

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)\.html$ itmes.php?id=$1 [L]
    RewriteRule ^(.*)/(.*)\.html$ description.php?id=$1& category=2 [L]

    My problem is… when I use for both url, only first url works 2nd url does not. But both url works independently. I don't get any error either.

    I plan to use more mod_rewrite urls, what am I doing wrong here? Do I need to change anything?
     
    rahman15, Mar 14, 2006 IP
  2. nicknick

    nicknick Peon

    Messages:
    429
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi. I'm no expert but it could be this. [L]

    That L indicates that it is the last rule in the list. So the server stops at your first command. Other than that, I'm not sure so I hope someone more experienced comes by. Good luck.
     
    nicknick, Mar 14, 2006 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #3
    There fighting over each other. No, this is an items page....er no, description page...NOOOO....

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^description/([^.]+)/([^.]+)\.html$ description.php?id=$1& category=2 [L]
    RewriteRule ^items/([^.]+)\.html$ itmes.php?id=$1 [L]

    If it's an items page, itmes.php and the actual script file should probably be changed to items.php just so it's spelled correctly!
     
    Nintendo, Mar 14, 2006 IP
  4. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #4
    the (.*)\.html in your first rule matches *anything*, including if it contains a forward slash. Try reversing the 2 rules
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    # This will match anything slash anything, and if it doesn't match
    # will continue on to the second rule
    RewriteRule ^(.*)/(.*)\.html$ description.php?id=$1& category=2 [L]
    RewriteRule ^(.*)\.html$ itmes.php?id=$1 [L]
    
    Code (markup):
    Also, it looks like you have the $1 and $2 mixed up- I would assume the category would be the "directory" and the id would be the "filename".
    RewriteRule ^(.*)/(.*)\.html$ description.php?id=$2& category=$1 [L]
    Code (markup):
     
    exam, Mar 14, 2006 IP
  5. rahman15

    rahman15 Well-Known Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    138
    #5
    Thanks Nintendo, you are the king.....

    It is items.php not itmes.php...just typing mistake.
     
    rahman15, Mar 15, 2006 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    Note exam's post on the order, if you want the category part before the item in the URL. Just change 1 to 2 and 2 to 1.

    And & category= shouldn't have that space.
     
    Nintendo, Mar 15, 2006 IP
  7. rahman15

    rahman15 Well-Known Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    138
    #7
    I should figure out by myself but I could not.
    How would I write mod_rewrite if I don’t want to use folder type system.
    For example:
    Instead of using:
    www.mysite.com/category.html < ----- one query string
    www.mysite.com/category/itemtype1.html < ----- two query strings
    www.mysite/category/itemtype2.html < ----- two query strings
    www.mysite.com/category/itemtype3.html < ----- two query strings

    I want to use this:
    www.mysite.com/category.html < ----- one query string
    www.mysite.com/category-itemtype1.html < ----- two query strings
    www.mysite.com/category-itemtype2.html < ----- two query strings
    www.mysite.com/category-itemtype3.html < ----- two query strings


    I hope you understand my question.
    Let me know if you need further clarification.


    I hope you understand my question.
    Let me know if you need further clarification.
     
    rahman15, Mar 15, 2006 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #8
    Change each / to \-

    Three of them.

    If the only change is going from 'directory' to looking like a .html file with -.
     
    Nintendo, Mar 15, 2006 IP