Strip a query param from a query string

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Strip a query param from a query string

07 Sep 2012, 17:14

I have 180 or so urls that contain a query string with a param of "style=summer"

EX: /?test=1&style=summer
Or: /?test=2&tester3&style=summer
Or: /?test4&test=5&test6&style=summer
etc etc

I would like to use a redirect to remove the query param "style=summer" without changing anything else. So the link:
/?test=1&style=summer would go to:
/?test=1

Any help would be appreciated

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

07 Sep 2012, 17:31

Note: the style=summer query param is not always at the end of the query string

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Strip a query param from a query string

09 Sep 2012, 17:44

Hello,

Try using the following:

Code: Select all
RewriteEngine on
RewriteBase /

RewriteCond %{QUERY_STRING} (.*)&style=summer(.*) [NC]
RewriteRule (.*) /$1?%1%2? [NC,R=301,L]


Regards
Andrew

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

10 Sep 2012, 16:55

I appreciate the help, Andrew. I did try that and I think we're close but it is removing too much of the query string. I tried this:

?subcatid=124&catid=55&efilter=zzzz&style=summer&maxshow=25&regionid=4,14,2,3&sfilter=a

but it returned the following (which returned a 404):

&maxshow=25&regionid=4,14,2,3&sfilter=a

So, it removed style=summer but also all parameters before it including the "?".

Any ideas on how I can fix this?

Thanks again!

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Strip a query param from a query string

10 Sep 2012, 17:08

That is strange, would you provide rewrite.log for this request?
Logging issues describe in FAQ

Regards
Andrew

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

10 Sep 2012, 18:51

I spoke with our IT department and they informed me that we do not have the rewrite.log. To me it looks like "(.*)&style=summer(.*)" is not split into 3 parts, it splits it to 2 vars. Is there any way to figure this out without the log?

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Strip a query param from a query string

11 Sep 2012, 00:11

Rewrite.log would explain us how that has gone, step by step...

I can't come up with the reason why it cuts the first part, before the "&style=summer". Why do you think it needs to be split into 3 parts? It takes the URL before the querystring, put it in front, then puts "?" and places the part that was in front of "&style=summer" and after it... so it's /$1?%1%2?


Regards
Andrew

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

11 Sep 2012, 21:23

I worked with IT today and got the log. Hope this helps:

(4) RewriteCond: input='sfilter=a&catid=55&efilter=zzzz&maxshow=25&style=summer&regionid=4,14,2,3' pattern='(.*)&style=summer(.*)' => matched
(1) escaping /activities/attractions/&regionid=4,14,2,3
(2) explicitly forcing redirect with http://www.thiswebsite.com/activities/a ... d=4,14,2,3
(2) internal redirect with /activities/attractions/?sfilter=a&catid=55&efilter=zzzz&maxshow=25&style=summer&regionid=4,14,2,3 [INTERNAL REDIRECT]


(2) init rewrite engine with requested uri /activities/attractions/&regionid=4,14,2,3/
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request d:\inetpub\web_sites\Website\web\isapi_mod_rewrite.ini
(3) applying pattern '^cfide/administrator/?$' to uri 'activities/attractions/&regionid=4,14,2,3/'
(3) applying pattern '^cfide/administrator/index.cfm?$' to uri 'activities/attractions/&regionid=4,14,2,3/'
(3) applying pattern '.*' to uri 'activities/attractions/&regionid=4,14,2,3/'
(4) RewriteCond: input='' pattern='redo=1' => not-matched
(3) applying pattern '(.*)' to uri 'activities/attractions/&regionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/&regionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/&regionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/&regionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/&regionid=4,14,2,3/'
(4) RewriteCond: input='' pattern='(.*)&style=summer(.*)' => not-matched

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Strip a query param from a query string

11 Sep 2012, 22:01

I edited it to make it more obvious... still doesn't explain that mess....
LEt's try smth different instead:

Code: Select all
RewriteEngine on
RewriteBase /

RewriteCond %{QUERY_STRING} ^([^&]+)&style=summer(.*) [NC]
RewriteRule (.*) http://www.domain.com/$1?%1%2? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^([^&]+)&([^&]+)&style=summer(.*) [NC]
RewriteRule (.*) http://www.domain.com/$1?%1&%2%3? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^([^&]+)&([^&]+)&([^&]+)&style=summer(.*) [NC]
RewriteRule (.*) http://www.domain.com/$1?%1&%2&%3%4? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^([^&]+)&([^&]+)&([^&]+)&([^&]+)&style=summer(.*) [NC]
RewriteRule (.*) http://www.domain.com/$1?%1&%2&%3&%4%5? [NC,R=301,L]


I know it looks ugly, but it's less universal and more hardcoded, so it should really work.

Regards
Andrew


User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Strip a query param from a query string

12 Sep 2012, 16:47

Amazing... very strange isssue. Ok, what build is that? We need to test it in other build. This must have worked from the beginning.

Regards
Andrew

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

17 Sep 2012, 13:35

Does anyone know why these rules are still not working?

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Strip a query param from a query string

17 Sep 2012, 13:44

Please, provide information on this build and we'll try to help you by testing these rules and/or taking a look at your configuration.

Regards
Andrew

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

17 Sep 2012, 13:46

Andrew, I am asking our IT dept about the version and build. Will let you know asap.

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

17 Sep 2012, 13:53

Here you go, Andrew. Thank you.

Helicon ISAPI_Rewrite configuration file
Version 3.1.0.89
AccessFileName isapi_mod_rewrite.ini

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Strip a query param from a query string

17 Sep 2012, 21:56

Well, I tested it in latest build #94 and it worked. I'm setting up #89 right now...
Can you upgrade? All you need to do is to back up httpd.conf, uninstall ISAPI_Rewrite and install the latest build. While uninstalling do not forget to check the checkbox "preserve all config files"

Regards
Andrew

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

18 Sep 2012, 22:23

I will work with my IT dept tomorrow and see if we can do this and then get back to you

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

20 Sep 2012, 14:48

Quick update - I am still working with my IT team to get the latest build installed on the server. As soon as I have this done, I will let you know where I am at. Thanks again for all your help.

User avatar
Posts: 12
Joined: 07 Sep 2012, 16:46

Re: Strip a query param from a query string

20 Sep 2012, 16:54

Looks like we will not have to update isapi after all. The following rules are working perfectly for us:


RewriteCond %{QUERY_STRING} ^style=summer(&|$)(.*?)$ [NC]
RewriteRule (.*) $1\?%2 [NC,R=301]

RewriteCond %{QUERY_STRING} ^(.*?)(&|^)style=summer(&|$)(.*?)$ [NC]
RewriteRule (.*) $1\?%1%3%4 [NC,R=301]

User avatar
Posts: 24
Joined: 27 Nov 2012, 21:57

Re: Strip a query param from a query string

30 Nov 2012, 00:04

I guess it will work completely once the update has been made.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests