SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Rewrite Unlimited Query

    Is there a way to have a mod rewrite to make friendly query strings

    something.php?city=brooklyn&state=ny&zip=11214&keyword=hi&keyword=another

    something/brooklyn/ny/11214/hi/another full example
    something/brooklyn/ny/11214/hi/ just 1 keyword
    something/brooklyn/ny/ just city and state

    with my limited knowledge i would have to do something like
    RewriteRule ^something-([^-][a-zA-z0-9_])$ /search.php?city=$1&state=$2&zip=$3 etc.... [L]
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Shay,

    Sure! I believe I got into this in my tutorial and discuss the limits to the simple method and how to extend to the allowed length of the URI (255 characters).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    LoL!! i'm always afraid to post a rewrite question cuz i know you will reply with 'check out my tutorial'

    but good stuff.. i found it in your tutorial.. i'll give it a try and if have question i post it.

    enjoy your weekend.
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.

  4. #4
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i tried the following script but have no clue what i means..

    if i added it.. I'm assuming search/city/state/zip will be added into query string?

    what's the difference between using your example as opposed to doing something like RewriteRule ^/?([a-zA-z0-9_]+)$ search.php?zg=$1
    and getting the query string from zg=brooklyn-ny-keyword-keyword. in this case i would have to split my query string.


    RewriteRule ^search/([a-z]+)/([a-zA-Z0-9_]+)(/(.*))*$ $4/?$1=$2 [QSA,N,L]

    RewriteCond %{QUERY_STRING} =
    RewriteRule ^$ search.php [L]
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Shay,

    Quote Originally Posted by Shaydez View Post
    LoL!! i'm always afraid to post a rewrite question cuz i know you will reply with 'check out my tutorial'
    OMG! I'm not allowed to try to protect myself from typing the same info/code repetitively? Yeah, it didn't work, did it?
    but good stuff.. i found it in your tutorial.. i'll give it a try and if have question i post it.

    enjoy your weekend.
    Until I get another question ...

    Quote Originally Posted by Shaydez View Post
    i tried the following script but have no clue what i means..

    if i added it.. I'm assuming search/city/state/zip will be added into query string?

    what's the difference between using your example as opposed to doing something like RewriteRule ^/?([a-zA-z0-9_]+)$ search.php?zg=$1
    and getting the query string from zg=brooklyn-ny-keyword-keyword. in this case i would have to split my query string.

    The difference is whether you use mod_rewrite to split the key/value pairs or your script (the script has tools to make that easier ... but your -'s can be easily misinterpreted).

    [code]# Please use the
    Code:
     ...
    wrapper
    RewriteRule ^search/([a-z]+)/([a-zA-Z0-9_]+)(/(.*))*$ $4/?$1=$2 [QSA,N,L]
    # Where do you get the name of the key from "something/brooklyn/ny/11214/hi/another full example" ?

    RewriteCond %{QUERY_STRING} = # No regex? This only requires "=" in the query string
    RewriteRule ^$ search.php [L]
    # and ^$ says that the URI is blank (the URL is just the domain).
    It's fortunate that my "developing regex" example is using a very similar URI development and the regex coding. Please take a look there as it covers the ORDER sequence of country/state/city (and your subsequent digits and verbiage can be assigned as required.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Addict Shaydez's Avatar
    Join Date
    Jul 2006
    Location
    Boca Raton, Florida
    Posts
    356
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    To answer my own question

    a Router is needed for unlimited params

    Or could us a based MVC (Controller/Method/Param/Param/Param/Param)
    Regex to handle that is

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
    Sr. Website Developer and Internet Marketing
    www.CarlosJa.com Note: If anyone
    needs to get ahold of me please feel free to email me through
    my site. Apparently i missed quite a few private messages.


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
  •