SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: sending unlimited variables within mod_rewright

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sending unlimited variables within mod_rewright

    I want to send unlimited number of variables within mod_rewright

    I used this rule to send three variables :
    PHP Code:
    RewriteRule ^([-a-zA-Z0-9\ \-\+\_\?]+)$                                                             index.php?var1=$1
    RewriteRule 
    ^([-a-zA-Z0-9\ \-\+\_\?]+)/$                                                            index.php?var1=$1
    RewriteRule 
    ^([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_]+)$                                       index.php?var1=$1&var2=$2
    RewriteRule 
    ^([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_]+)/$                                      index.php?var1=$1&var2=$2
    RewriteRule 
    ^([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_\/\*]+)$          index.php?var1=$1&var2=$2&var3=$3
    RewriteRule 
    ^([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_\/\*]+)/$         index.php?var1=$1&var2=$2&var3=$


    when I wanted to send 4 , I added the variable and its rule after the previous one , but this didn't work properly ...

    PHP Code:
    RewriteRule ^([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_\/\*]+)/([-a-zA-Z0-9\ \-\+\_\/\*]+)$          index.php?var1=$1&var2=$2&var3=$3&var4=$4
    RewriteRule 
    ^([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_]+)/([-a-zA-Z0-9\ \-\+\_\/\*]+)/([-a-zA-Z0-9\ \-\+\_\/\*]+)/$         index.php?var1=$1&var2=$2&var3=$3&var4=$

    when requesting a link such as :

    http://site.com/1st/2nd/3rd/4th/5th

    The result of print_r function was :

    PHP Code:
    Array ( [var1] => 1st [var2] => 2nd [var3] => 3rd/4th/5th 

    I know that this method is very silly , and it proofed that !

    what if I want to send 40 variables and using the modrewright engine with them ???

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    14,356
    Mentioned
    64 Post(s)
    Tagged
    1 Thread(s)

    slash

    Why is the slash one of the characters being captured?
    ([-a-zA-Z0-9 -+_/*]+)

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

    Apache has a limit of 9 variables that you can create with mod_rewrite. Forty is both absurd and impossible (withing chaining).

    Regards,

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

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what if I used one variable with unlimited number of slashes for its value ...?
    PHP Code:
    RewriteRule ^([-a-zA-Z0-9\ \*\-\=\+\_\@\/\*]+)$  index.php?request=$
    then I can use explode() function to separate the variables ...

    for example :

    the request :

    PHP Code:
    http://localhost/test/1st/2nd/3rd/4/5/6/7/8/9/10/11/12/13 
    PHP Code:
    <?php

    print_r
    ($_GET);

    ?>
    if we used print_r function , this will be the result :

    PHP Code:
    Array ( [request] => 1st/2nd/3rd/4/5/6/7/8/9/10/11/12/13 

    PHP Code:
    <?php

    $variables 
    explode('/'$_GET['request'] );

    ?>
    so I have unlimited number of variables within the array $variables[] ...

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    14,356
    Mentioned
    64 Post(s)
    Tagged
    1 Thread(s)

    forty

    That may very well work, but ......
    If the idea behind using "user friendly" URLs instead of GET vars is to have friendly URLs, IMHO having that many levels of virtual directories is less friendly than a GET variable.
    If this is because your current database structure requires this kind of manipulation, then I imagine you will have performance issues at some point. You may want to head on over to the database forum and optimize your tables first before getting too entrenched.

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no .. no .. I know that this way of processing is very confusing ...
    It is just an idea to solve the problem of the request .. and just to take my safe margin if someone wanted to create a component with 3 variables or more ..

    I think when I have to design a pluggable system , I have to think about the worse probabilities that would happen ..

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    al,

    There was a way discussed here some months back which involved iterating through a {REQUEST_URI} slicing off key/value pairs while building a query string (another gem from pippo which I repeated some time afterward for those who'd missed it). Please do a search for chaining of variables, multiple key/value pairs, etc.

    Also, remember that Mitt's correct on this one! Too much work for Apache to do - better left to PHP as you've suggested (redirect everything that's not a file/directory to process.php as a query string and explode there).

    Regards,

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

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
  •