new_rewrite and multiple querystring parameters

Discussion in 'Setting-up protection' started by bjk68, Nov 15, 2008.

  1. bjk68

    bjk68 New Member

    Joined:
    Nov 15, 2008
    Messages:
    24
    I noticed that new_rewrite supports only the first querystring parameter :mad: . The other parameters are lost, because the &-signs between them are not escaped.

    I modified the .htaccess file as follows, to support more querystring parameters (now the maximum 5 parameters) :) :

    Code:
    ## if user is not authorized, redirect to login page
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^(.*)$ http://www.domein.nl/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://www.domein.nl%{REQUEST_URI} [L,R]
    RewriteCond %{QUERY_STRING} ^([^&]+)$
    RewriteRule ^(.*)$ http://www.domein.nl/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://www.domein.nl%{REQUEST_URI}?%1 [L,R]
    RewriteCond %{QUERY_STRING} ^([^&]+)&([^&]+)$
    RewriteRule ^(.*)$ http://www.domein.nl/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://www.domein.nl%{REQUEST_URI}?%1\%26%2 [NE,L,R]
    RewriteCond %{QUERY_STRING} ^([^&]+)&([^&]+)&([^&]+)$
    RewriteRule ^(.*)$ http://www.domein.nl/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://www.domein.nl%{REQUEST_URI}?%1\%26%2\%26%3 [NE,L,R]
    RewriteCond %{QUERY_STRING} ^([^&]+)&([^&]+)&([^&]+)&([^&]+)$
    RewriteRule ^(.*)$ http://www.domein.nl/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://www.domein.nl%{REQUEST_URI}?%1\%26%2\%26%3\%26%4 [NE,L,R]
    RewriteCond %{QUERY_STRING} ^([^&]+)&([^&]+)&([^&]+)&([^&]+)&([^&]+)$
    RewriteRule ^(.*)$ http://www.domein.nl/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://www.domein.nl%{REQUEST_URI}?%1\%26%2\%26%3\%26%4\%26%5 [NE,L,R]
    ########### AMEMBER FINISH ####################
  2. bjk68

    bjk68 New Member

    Joined:
    Nov 15, 2008
    Messages:
    24
    Alternative, better solution

    The last RewriteRule should be unconditional. So I created an alternative solution, which also compiles faster, because the regular expressions are less complex.

    The solution is designed for a maximum of 5 querystring parameters. You could of course add more to the solution.

    The trick is to replace the &-characters by %26. This way the &'s are escaped, so they remain recognised as parameters on the url, that is being passed to the login.php.

    Code:
    ## if user is not authorized, redirect to login page
    RewriteCond %{QUERY_STRING} ^(.+)&(.+)&(.+)&(.+)&(.+)$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://%{HTTP_HOST}%{REQUEST_URI}?%1\%26%2\%26%3\%26%4\%26%5 [NE,L,R]
    RewriteCond %{QUERY_STRING} ^(.+)&(.+)&(.+)&(.+)$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://%{HTTP_HOST}%{REQUEST_URI}?%1\%26%2\%26%3\%26%4 [NE,L,R]
    RewriteCond %{QUERY_STRING} ^(.+)&(.+)&(.+)$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://%{HTTP_HOST}%{REQUEST_URI}?%1\%26%2\%26%3 [NE,L,R]
    RewriteCond %{QUERY_STRING} ^(.+)&(.+)$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://%{HTTP_HOST}%{REQUEST_URI}?%1\%26%2 [NE,L,R]
    RewriteCond %{QUERY_STRING} ^(.+)$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://%{HTTP_HOST}%{REQUEST_URI}?%1 [L,R]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/amember/plugins/protect/new_rewrite/login.php?v=-1&url=http://%{HTTP_HOST}%{REQUEST_URI} [L,R]
    ########### AMEMBER FINISH ####################

Share This Page