Strip a query param from a query string
20 posts
• Page 1 of 1
Strip a query param from a query string
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
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
Re: Strip a query param from a query string
Note: the style=summer query param is not always at the end of the query string
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Strip a query param from a query string
Hello,
Try using the following:
Regards
Andrew
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
Re: Strip a query param from a query string
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®ionid=4,14,2,3&sfilter=a
but it returned the following (which returned a 404):
&maxshow=25®ionid=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!
?subcatid=124&catid=55&efilter=zzzz&style=summer&maxshow=25®ionid=4,14,2,3&sfilter=a
but it returned the following (which returned a 404):
&maxshow=25®ionid=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!
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Strip a query param from a query string
That is strange, would you provide rewrite.log for this request?
Logging issues describe in FAQ
Regards
Andrew
Logging issues describe in FAQ
Regards
Andrew
Re: Strip a query param from a query string
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?
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Strip a query param from a query string
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
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
Re: Strip a query param from a query string
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®ionid=4,14,2,3' pattern='(.*)&style=summer(.*)' => matched
(1) escaping /activities/attractions/®ionid=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®ionid=4,14,2,3 [INTERNAL REDIRECT]
(2) init rewrite engine with requested uri /activities/attractions/®ionid=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/®ionid=4,14,2,3/'
(3) applying pattern '^cfide/administrator/index.cfm?$' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '.*' to uri 'activities/attractions/®ionid=4,14,2,3/'
(4) RewriteCond: input='' pattern='redo=1' => not-matched
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(4) RewriteCond: input='' pattern='(.*)&style=summer(.*)' => not-matched
(4) RewriteCond: input='sfilter=a&catid=55&efilter=zzzz&maxshow=25&style=summer®ionid=4,14,2,3' pattern='(.*)&style=summer(.*)' => matched
(1) escaping /activities/attractions/®ionid=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®ionid=4,14,2,3 [INTERNAL REDIRECT]
(2) init rewrite engine with requested uri /activities/attractions/®ionid=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/®ionid=4,14,2,3/'
(3) applying pattern '^cfide/administrator/index.cfm?$' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '.*' to uri 'activities/attractions/®ionid=4,14,2,3/'
(4) RewriteCond: input='' pattern='redo=1' => not-matched
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(3) applying pattern '(.*)' to uri 'activities/attractions/®ionid=4,14,2,3/'
(4) RewriteCond: input='' pattern='(.*)&style=summer(.*)' => not-matched
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Strip a query param from a query string
I edited it to make it more obvious... still doesn't explain that mess....
LEt's try smth different instead:
I know it looks ugly, but it's less universal and more hardcoded, so it should really work.
Regards
Andrew
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
Re: Strip a query param from a query string
Thank you very much for the help. Unfortunately, this is not working yet. I added the redirects and tested. Here are the results:
TEST URL: www.ThisWebsite.com/activities/pools/?s ... &sfilter=a
RETURNED: http://www.ThisWebsite.com/activities/p ... sfilter=a/
TEST URL: www.ThisWebsite.com/activities/attracti ... yle=summer
RETURNED: www.ThisWebsite.com/activities/attracti ... yle=summer
TEST URL: www.ThisWebsite.com/hotels/casino-resor ... tartrow=26
RETURNED: http://www.ThisWebsite.com/hotels/casin ... artrow=26/
TEST URL: www.ThisWebsite.com/activities/attracti ... d=4,14,2,3
RETURNED: http://www.ThisWebsite.com/activities/a ... =4,14,2,3/
TEST URL: www.ThisWebsite.com/activities/attracti ... ng=nothing
RETURNED: http://www.ThisWebsite.com/activities/a ... ng=nothing
TEST URL: www.ThisWebsite.com/activities/attracti ... yle=summer
RETURNED: http://www.ThisWebsite.com/activities/a ... =4,14,2,3/
TEST URL: www.ThisWebsite.com/activities/pools/?s ... &sfilter=a
RETURNED: http://www.ThisWebsite.com/activities/p ... sfilter=a/
TEST URL: www.ThisWebsite.com/activities/attracti ... yle=summer
RETURNED: www.ThisWebsite.com/activities/attracti ... yle=summer
TEST URL: www.ThisWebsite.com/hotels/casino-resor ... tartrow=26
RETURNED: http://www.ThisWebsite.com/hotels/casin ... artrow=26/
TEST URL: www.ThisWebsite.com/activities/attracti ... d=4,14,2,3
RETURNED: http://www.ThisWebsite.com/activities/a ... =4,14,2,3/
TEST URL: www.ThisWebsite.com/activities/attracti ... ng=nothing
RETURNED: http://www.ThisWebsite.com/activities/a ... ng=nothing
TEST URL: www.ThisWebsite.com/activities/attracti ... yle=summer
RETURNED: http://www.ThisWebsite.com/activities/a ... =4,14,2,3/
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Strip a query param from a query string
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
Regards
Andrew
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Strip a query param from a query string
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
Regards
Andrew
Re: Strip a query param from a query string
Andrew, I am asking our IT dept about the version and build. Will let you know asap.
Re: Strip a query param from a query string
Here you go, Andrew. Thank you.
Helicon ISAPI_Rewrite configuration file
Version 3.1.0.89
AccessFileName isapi_mod_rewrite.ini
Helicon ISAPI_Rewrite configuration file
Version 3.1.0.89
AccessFileName isapi_mod_rewrite.ini
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Strip a query param from a query string
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
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
Re: Strip a query param from a query string
I will work with my IT dept tomorrow and see if we can do this and then get back to you
Re: Strip a query param from a query string
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.
Re: Strip a query param from a query string
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]
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]
- tidaltides
- Posts: 24
- Joined: 27 Nov 2012, 21:57
Re: Strip a query param from a query string
I guess it will work completely once the update has been made.
20 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests