Need help in mod_rewrite

Discussion in 'Apache' started by silverf0x, Oct 25, 2009.

  1. #1
    I have a page details.php with URL domain.com/details.php?id=a&s=b
    I want it show domain.com/details/a/b.htm in address bar.

    I write this rule in .htaccess :
    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^details/([^/]+)/([^/]+).html /details.php?id=$1&s=$2 [NC]
    </IfModule>

    But it not works. I confused what's wrong with my rule ? Help me please
     
    silverf0x, Oct 25, 2009 IP
  2. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #2
    The following should work

    RewriteRule ^details/([^/]+)/([^/]+)\.html details.php?id=$1&s=$2 [NC]

    If not are you getting any error messages or anything?
     
    tolra, Oct 26, 2009 IP
  3. silverf0x

    silverf0x Well-Known Member

    Messages:
    535
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #3
    Nothing error message, but it not works. My URL still like before
     
    silverf0x, Oct 26, 2009 IP
  4. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #4
    I tried it on one of our servers here and it's working for me, the whole .htaccess I used is:
    RewriteEngine on
    RewriteRule ^details/([^/]+)/([^/]+)\.html details.php?id=$1&s=$2 [NC]
    
    Code (markup):
    Your host does support mod_rewite?

    One thing I just noticed is you have:
    I assume that's a typo and you meant:
    domain.com/details/a/b.html
    Code (markup):
    The rewrite rule above and your original both need .html if you want .htm the the following should do it:
    RewriteEngine on
    RewriteRule ^details/([^/]+)/([^/]+)\.htm details.php?id=$1&s=$2 [NC]
    
    Code (markup):
     
    tolra, Oct 26, 2009 IP
  5. silverf0x

    silverf0x Well-Known Member

    Messages:
    535
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #5
    I asked about this to my host and they said that support mod-Rewrite and maybe my code is wrong. They told me to review my code again :(

    It's okay if URL will end .htm or .html. I just want to make the URL clean and SEO friendly

    But thanks for your help
     
    silverf0x, Oct 26, 2009 IP
  6. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #6
    I'm just wondering if I'm trying to fix the wrong thing.
    So if you manually enter details/a/b.html into your browser address bar does the correct page show?

    Then when you say your URLs like before do you mean that links on your site are still in the form domain.com/details.php?id=a&s=b they will be, you will have to modify the script and/or static links to be in the new format, rewrite only works on the incoming data not the forming of the URLs.
     
    tolra, Oct 26, 2009 IP
  7. silverf0x

    silverf0x Well-Known Member

    Messages:
    535
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #7
    ya ya ya....i think i understand now what's wrong.

    my mindset was wrong. thanks bro for your help
     
    Last edited: Oct 26, 2009
    silverf0x, Oct 26, 2009 IP