How to capture the URL

Discussion in 'PHP' started by Davidf25sc, Jun 20, 2007.

  1. #1
    Hello,

    Have you seen those scripts that captures the url to display items from a database for example?
    The links on the site goes like : http://www.example.com/show_items_ma/
    but there is not a folder called "show_items_ma" in the website, this url is captured and processed so that a file, lets say "showitem.php" is the one that gets called and somehow gets the parameters to work with.
    Instead of putting something like http://www.example.com/showitems.php?id=ma they make it look like a directory.

    The same happens sometimes with html files, they show links like http://www.example.com/show_item_23.html, but there is no file called "show_item_23.html", this url is once again captured and processed.

    You can see examples of what im talking about at
    http://www.homesbyowner.com/ <-this ones works with directories
    or http://www.homesonsale.co.uk/ <- they work with the .html


    I was wondering if you can give me some tips or clues about how this thechnic is done, Thanks a lot.

    David.
     
    Davidf25sc, Jun 20, 2007 IP
  2. Germ

    Germ Active Member

    Messages:
    154
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #2
    It's htaccess mod_rewrite.
    Have a look at http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
    Apache rewrites it and sends a query to a handling script which processes it and returns HTML as if the file/folder realy was
    If you need further assistance - PM me
     
    Germ, Jun 20, 2007 IP
  3. Davidf25sc

    Davidf25sc Active Member

    Messages:
    165
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thanks Germ for the comment, is there any other way? is it done with apache and .htaccess edition only?
     
    Davidf25sc, Jun 20, 2007 IP
  4. Germ

    Germ Active Member

    Messages:
    154
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #4
    I believe this is the only way to do it on a Unix system. I do not know how this is done on windows servers, if possible at all.
     
    Germ, Jun 20, 2007 IP
  5. uniqueasitis

    uniqueasitis Peon

    Messages:
    661
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #5
    actually there is another way known as apache look back feature. But you would have to format the url as follows
    example.com/processor/show_items_ma/
    Note the processor portion. That is the script which will do the processing. This is how it works. When apache cannot find the show_items_ma it looks back. If it finds processor then it executes it. To see an example try this
    forums.digitalpoint.com/showthread.php?t=372628
    is the url for this page change it to
    forums.digitalpoint.com/showthread.php?t=372628/hellyeahustinrules
    press enter the same page will display.
    Now if you set the file force type directive to force files with no extensions to be prased as .php files then the processor file will be prased as a php file allowing you to processor the url. You could use the PATH_INFO to get the show_tables_ma protion of the url and then have the script open the relevant file select the relevant database table field. If you need more help msg me on the forum. Good luck!
     
    uniqueasitis, Jun 20, 2007 IP
  6. Davidf25sc

    Davidf25sc Active Member

    Messages:
    165
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Thank you very much for your tips, i have one more question, is there a way to do this without working with the htaccess file?
     
    Davidf25sc, Jun 23, 2007 IP