SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2014
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess doesn't work as expected

    I'm quite(absolutely) new in mod_rewrite and trying to do 'friendly URL's' but there is some problem that I can't figured it out. So, I have categories and the url is
    Code:
    /pic.php?cat_id=1
    After rewrite it I get this url
    
    /pic/1
    When category load there is 1 image and button 'Next'. When I click on 'Next' my URL is
    Code:
    pic.php?cat_id=1&id=2
    After rewrite
    pic/1/2
    And here Is the problem. When I click 'Next' forn next image the page is refreshed, the image is sam and the url became
    Code:
    pic/1/1/2
    And after every 'Next' click put one more /1/ Here is the .htaccess that I use right now
    Code:
    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^pic/([0-9]+)(/([0-9]+))? pic.php?cat_id=$1&line[0]=$3 [L,QSA]
    RewriteRule ^pic/([0-9]+)? pic.php?cat_id=$1 [L,QSA]
    And here are both links
    Code:
    <a href="pic/'. $res['cat_id'] .'"> <--- for selecting category
    <a href="'.$cat_id.'/'.$line[0].'"> <--- next image in that category
    And if I choose another category while I'm in category my URL become
    Code:
    pic/1/2/pic/2/ <---put other category url next to the current category
    Where I'm wrong. I can gues is in my href's but I don't know what exactly?

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Because your HTML is using relative links. Try root-relative instead.

    Code:
    <a href="/pic/'. $res['cat_id'] .'"> <--- for selecting category
    <a href="/pic/'.$cat_id.'/'.$line[0].'"> <--- next image in that category
    "First make it work. Then make it better."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •