.HTACCESS file help

Discussion in 'PHP' started by afhayati, Jun 26, 2007.

  1. #1
    Hi everybody

    I have a link such as : www.mysite.com/product.php?id=123
    and another link as : www.mysite.com/details.php?id=123

    the product name of the code 123 is (for example) : PRD1

    I want to change my Links to :

    www.mysite.com/PRD1/ instead of www.mysite.com/product.php?id=123

    and for 2nd link use this one:
    www.mysite.com/PRD1/details/ instead of www.mysite.com/details.php?id=123

    How to do this with .htaccess file? is it possible?
     
    afhayati, Jun 26, 2007 IP
  2. Nefarious

    Nefarious Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    No expert but yes its possible.

    You will need to look up regex. (regular expression)

    Here is something real quick it prolly won't work but you can try it

    RewriteRule ^(.*)$\/ product.php?id=$1
    RewriteRule ^(.*)$\/details\/ details.php?id=$1


    ^ is the start, ex: after the trailing slash in the url, http://site.com/
    (.*)$ should be everything between the trailing slash and the next slash.
    \/ is an escaped slash that should be in the url.

    Hopefully this helps you a bit, and maybe someone else who knows regex will jump in! hehe
     
    Nefarious, Jun 26, 2007 IP
  3. afhayati

    afhayati Active Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #3
    Thank u

    Now if I want to use a string id such as (id=7cd3g002) , what should to do?

    may I use the same code? like this:

     
    afhayati, Jun 26, 2007 IP
  4. Nefarious

    Nefarious Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes.

    .* means everything, letters and numbers and any length.
     
    Nefarious, Jun 26, 2007 IP
  5. afhayati

    afhayati Active Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #5
    Thanks

    Another question, why you use (details\/ details) 2 times?

    [sorry for lots of questions :eek: ]
     
    afhayati, Jun 26, 2007 IP
  6. Nefarious

    Nefarious Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    the 2nd details is details.php, tab didnt come out right on post.
     
    Nefarious, Jun 26, 2007 IP
  7. cjjune

    cjjune Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi

    I want to manipulate html file using .htaccess

    By the way the error message from the ApACHE log file is

    [Sun Jun 24 17:18:14 2007] [error] [client 127.0.0.1] Filename is not valid: d:/easyphp1-8/www/zen-cart-v1.3.7-full-fileset-12302006/piggy-guest-book-p-
    234:2bfedfbc8c496a2b3f98e69e988d177e.html

    So anyone has any idea how to remove the random numbers and letters after the colon:)) sign? Colon :)) sign should also be removed.

    How to do it using .htaccess?
     
    cjjune, Jun 26, 2007 IP