SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Zealot iamkoa's Avatar
    Join Date
    Mar 2005
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face How to place submitted form variables in URL like/this

    I'm trying to make search engine friendly URLs, and I'd like to create a search page that works in the same way as the rest of my website.

    After submitting a form, I'd like the form data to appear in a URL like so:

    http://mysite.com/search/name/josh/

    "search" is the actual PHP search page, "name" is one of the option fields submitted by the form, and "josh" is a name inserted via a text field in a form.

    How can I make an HTML form (using PHP) submit itself in a URL-friendly manner?

    Thanks a lot!
    Iamkoa, LLC
    Podlodge - Software, tools, and hacks for the iPod

  2. #2
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's Mod ReWriting. Take a look here to learn about this.
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  3. #3
    SitePoint Zealot iamkoa's Avatar
    Join Date
    Mar 2005
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks F4nat1c, I gave that website a read... however I'm still confused as to how to accomplish what I need. Can you explain?
    Iamkoa, LLC
    Podlodge - Software, tools, and hacks for the iPod

  4. #4
    SitePoint Zealot iamkoa's Avatar
    Join Date
    Mar 2005
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Update:

    This is the form string I'm trying to change:
    http://mysite.com/search/?area=foo&find=bar

    And I'm trying to change it too:
    http://mysite.com/search/foo/bar/

    This is what I wrote in .htaccess:
    Code:
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{QUERY_STRING} ^area\=([^&]+)\&find\=([^&]+)$
    RewriteRule ^$ /search/%1/%2/ [R=301,L]
    My htaccess code doesn't seem to change anything...
    Iamkoa, LLC
    Podlodge - Software, tools, and hacks for the iPod

  5. #5
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try

    RewriteEngine on
    RewriteBase /
    RewriteRule ^search/foo/bar/$ index.php?area=foo&find=bar

  6. #6
    SitePoint Zealot iamkoa's Avatar
    Join Date
    Mar 2005
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried that. Doesn't seem to work.

    I am supposed to actually see the url change, correct?
    Iamkoa, LLC
    Podlodge - Software, tools, and hacks for the iPod

  7. #7
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  8. #8
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please post the URL that you're trying to access and I'll try figure out what's wrong

  9. #9
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As an aside, I tried this awhile back and got it going on my actual site, but on my PC running apache, I could not get it to work.

    Anyone run into that?

    Thanks

    mk

  10. #10
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh! I see!
    are you getting a not found error or soemthing?

  11. #11
    SitePoint Zealot iamkoa's Avatar
    Join Date
    Mar 2005
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting... I'm testing this via my PC running Apache.

    And I87, I'm simply submitting a form via the "get" method and trying to turn the resulting URL into a friendly URL like a showed above.

    So anyone have a working Mod Rewrite I can sample?
    Iamkoa, LLC
    Podlodge - Software, tools, and hacks for the iPod

  12. #12
    Counter-Striker
    Join Date
    Sep 2005
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    Dont know if this will help but misewell post it
    Code:
    RewriteEngine On
    RewriteRule ^search/name/(.*)/ /search.php?search=$1
    RewriteRule ^search/name/(.*) /search.php?search=$1
    Its got to be in .htaccess

  13. #13
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think i kno what you're tryin to do

    there is no way to submit it directly to a mod-rewritten page. you will need to submit it to a page, then redirect it to a page in the format you want, then that will be mod-rewrriten to load on the page you want. example:

    search.php -> search.php?q=widgets&page=10&category=buttons -> /search/widgets/10/buttons/ -> search_parser.php?q=widgets&page=10&category=buttons

    this may be more work than its worth, and normally i don't find it useful enough to do all of this just to get my page in a decent format.

  14. #14
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you actually could make the form submit in that way, but it would require javascript to evaluate the forms field names/values and use that to craft a new action for the form.

  15. #15
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Err... do you actually have mod_rewrite installed?

    (Up to now,no one's askedand you haven't said.)
    Zealotry is contingent upon 100 posts and addiction 200?

  16. #16
    SitePoint Zealot iamkoa's Avatar
    Join Date
    Mar 2005
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the replies.

    I do have mod_rewrite installed, so I know that's not the issue.

    I guess if it's not possible to directly submit from a forum into such a URL without javascript, I'm going to drop the idea completely. It's too bad this method can't be used.

    If you guys think it's worth using Javascript to accomplish the task, I'll do it (with your help), otherwise I'm going to use the typical form GET method.
    Iamkoa, LLC
    Podlodge - Software, tools, and hacks for the iPod


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
  •