Preserve query on url re-write

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 8
Joined: 22 Sep 2013, 04:50

Preserve query on url re-write

20 Aug 2015, 07:48

Hi,
Can anyone help me create a rule to preserve query values on a re-written url?

I have a search form that when someone performs a search it gets posted to

/default.asp?pn=search
using this rule:
RewriteRule ^search$ /default.asp?pn=search [NC,L]

How can I set up the rule to preserve the following as a querystring
e.g. /search?zoom_query=elgar&zoom_page=2&zoom_per_page=10

I want to be re-written as:
/default.asp?pn=search&zoom_query=elgar&zoom_page=2&zoom_per_page=10


I have tried this:
RewriteCond %{QUERY_STRING} ^zoom_query=([^&]+)$
RewriteRule ^default\.asp$ /default.asp?pn=search$1

but it didn't work
Many thanks

User avatar
Posts: 8
Joined: 22 Sep 2013, 04:50

Re: Preserve query on url re-write

21 Aug 2015, 00:29

I think my problem is in the regex
In the log files I found this:

RewriteCond: input='zoom_query=elgar&zoom_cat[]=22&zoom_per_page=10&zoom_and=1&zoom_sort=0' pattern='^zoom_query=([^&]+)$' => not-matched

I'm not very good at understanding the regex patterns.
Can anyone help me construct a regex that will match all querystring parameters?

Many thanks.

User avatar
Posts: 8
Joined: 22 Sep 2013, 04:50

Re: Preserve query on url re-write

21 Aug 2015, 04:05

I think I fixed it - if anyone is interested.
However this may not be the ideal solution, but it works for me.

RewriteCond %{QUERY_STRING} ^zoom_query=([^~]+)$ [NC]
RewriteRule ^search$ /default.asp?pn=search&zoom_query=%1 [NC,L]

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 20 guests