Link to home
Start Free TrialLog in
Avatar of kuzmar
kuzmarFlag for Slovenia

asked on

Apache mod_rewrite redirect more that 10 query strings URL in .htaccess

I have a very long URL. More thant 10 query strings:

http://www.domain.com/test.php?aq=arg1&sw=arg2&de=arg3&fr=>=&hy=&ju=&ki=&lo=&cp=&za=&xs=&cd=&vf=

I want to redirect this page to:

http://www.domain.com/makemyday/art1/arg2/arg3 ...

Following .htaccess works only till the 9th parameter.
RewriteCond %{QUERY_STRING} ^aq=([^&]*)&sw=([^&]*)   ... repeating the same here ...  [NC]
RewriteRule ^test\.php$ /makemyday/%1/%2/%3/%4/%5/%6/%7/%8/%9/%10/%11/%12/%13/%14? [R=301,L]
RewriteRule ^makemyday/(.*)/ ... repeating the same here ... (.*)/?$ test.php?search=do&aq=$1&sw=$2 ... repeating the same here ... [L,NC]

Open in new window


I get the following result:

http://www.domain.com/makemyday/arg1/arg2/arg3////////1/2/3/4
Avatar of kuzmar
kuzmar
Flag of Slovenia image

ASKER

Maybe it is a similar solution ... i will rephrase the question:

How to get more than 10 query string variables from this URL:

http://www.domain.com/makemyday/first/arg/1/fdrh/s/dd/1/sdf/sdf/ad/sdfd/sdfasdf/aa/34rgf

RewriteRule ^makemyday/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/?$ test.php?make=Y&aq=$1&sw=$2&de=$3&fr=$4&gt=$5&hy=$6&ju=$7&ki=$8&lo=$9&cp=$10&za=$11&xs=$12&cd=$13&vf=$14 [L,NC]

Open in new window


I am only able to get first 9. Here is the $_GET array:
(
    [make] => Y
    [kw] => first
    [tp] => arg
    [ac] => 1
    [ae] => fdrh
    [ct] => s
    [zp] => dd
    [mi] => 1
    [ma] => sdf
    [be] => sdf
    [ba] => first0
    [yb] => first1
    [sf] => first2
    [vw] => first3
    [ft] => first4
)

Open in new window

Avatar of Steve Bink
From the manual, at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond:

RewriteRule backreferences: These are backreferences of the form $N (0 <= N <= 9), which provide access to the grouped parts (in parentheses) of the pattern, from the RewriteRule which is subject to the current set of RewriteCond conditions..

RewriteCond backreferences: These are backreferences of the form %N (1 <= N <= 9), which provide access to the grouped parts (again, in parentheses) of the pattern, from the last matched RewriteCond in the current set of conditions.

If your query strings are as complicated as that, consider moving the redirection process to your code.
ASKER CERTIFIED SOLUTION
Avatar of Tony McCreath
Tony McCreath
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial