You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Dave Wreski <dw...@guardiandigital.com.INVALID> on 2024/01/04 19:53:30 UTC

[users@httpd] Rewrite query string?

Hi,

I'm trying to replace "searchword" with just "search" in the following URL:

https://example.com/search?searchword=CVE-2021-4014&Search=

I've tried the following RewriteCond/RewriteRule in various forms, but 
not sure what I'm doing wrong.

RewriteCond %{QUERY_STRING} ^searchword=(.*)
RewriteRule ^   q=$1 [NC,L]

Ideas for what I'm doing wrong would be greatly appreciated.

Thanks,
Dave


Re: [users@httpd] Rewrite query string?

Posted by Eric Covener <co...@gmail.com>.
> RewriteRule ^/search$ %{REQUEST_URI}?search=%1 [NC,L]

probably should restrict to /search as edited

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Rewrite query string?

Posted by Antony Stone <An...@apache.open.source.it>.
On Thursday 04 January 2024 at 23:18:52, Frank Gingras wrote:

> On Thu, Jan 4, 2024 at 5:03 PM Will Fatherley <we...@gmail.com> wrote:
> > 
> > RewriteCond to know. Also, isn’t that the “starts with” operator, ^? What
> > if the parameter comes second? A bit verbose, but:
> >  ^.*searchword=(\w{1})[&]{0,1}.*$
> 
> You don't want to use ^.* - just use the substring match behaviour by
> removing ^.* if you want to match searchword anywhere in the value.

Same thing applies for .*$ - leave it out.


Antony.

-- 
The GPL-Violations project was formed on this day in 2004.
https://gpl-violations.org/

                                                   Please reply to the list;
                                                         please *don't* CC me.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Rewrite query string?

Posted by Frank Gingras <th...@apache.org>.
On Thu, Jan 4, 2024 at 5:03 PM Will Fatherley <we...@gmail.com> wrote:

>
> https://example.com/search?searchword=CVE-2021-4014&Search=
>>
>> I've tried the following RewriteCond/RewriteRule in various forms, but not sure what I'm doing wrong.
>>
>> RewriteCond %{QUERY_STRING} ^searchword=(.*)
>> RewriteRule ^   q=$1 [NC,L]
>>
>> Ideas for what I'm doing wrong would be greatly appreciated.
>>
>> Is the query parameter case sensitive? That’d be important for
> RewriteCond to know. Also, isn’t that the “starts with” operator, ^? What
> if the parameter comes second? A bit verbose, but:
>
>  ^.*searchword=(\w{1})[&]{0,1}.*$
>

You don't want to use ^.* - just use the substring match behaviour by
removing ^.* if you want to match searchword anywhere in the value.

Re: [users@httpd] Rewrite query string?

Posted by Will Fatherley <we...@gmail.com>.
>
> https://example.com/search?searchword=CVE-2021-4014&Search=
>>
>> I've tried the following RewriteCond/RewriteRule in various forms, but not sure what I'm doing wrong.
>>
>> RewriteCond %{QUERY_STRING} ^searchword=(.*)
>> RewriteRule ^   q=$1 [NC,L]
>>
>> Ideas for what I'm doing wrong would be greatly appreciated.
>>
>> Is the query parameter case sensitive? That’d be important for
> RewriteCond to know. Also, isn’t that the “starts with” operator, ^? What
> if the parameter comes second? A bit verbose, but:
>
>  ^.*searchword=(\w{1})[&]{0,1}.*$
>

Whoops, meant to add a comma in the capturing group. Also the end is
ambiguous. Maybe

searchword=(\w{1,})

Should match all the way to the end of the query value (& is not in \w), or
the end the query string if it’s the last parameter.

>

Re: [users@httpd] Rewrite query string?

Posted by Will Fatherley <we...@gmail.com>.
> https://example.com/search?searchword=CVE-2021-4014&Search=
>
> I've tried the following RewriteCond/RewriteRule in various forms, but not sure what I'm doing wrong.
>
> RewriteCond %{QUERY_STRING} ^searchword=(.*)
> RewriteRule ^   q=$1 [NC,L]
>
> Ideas for what I'm doing wrong would be greatly appreciated.
>
> Is the query parameter case sensitive? That’d be important for RewriteCond
to know. Also, isn’t that the “starts with” operator, ^? What if the
parameter comes second? A bit verbose, but:

 ^.*searchword=(\w{1})[&]{0,1}.*$

Re: [users@httpd] Rewrite query string?

Posted by Eric Covener <co...@gmail.com>.
> However, this change is not reflected in the Location bar in my browser.

You can append the 'R' flag if you need it to redirect. Otherwise,
just the internal representation is changed.

RewriteRule ^ %{REQUEST_URI}?search=%1 [NC,L,R]

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Rewrite query string?

Posted by Dave Wreski <dw...@guardiandigital.com.INVALID>.
>> https://example.com/search?searchword=CVE-2021-4014&Search=
>>
>> I've tried the following RewriteCond/RewriteRule in various forms, but not sure what I'm doing wrong.
>>
>> RewriteCond %{QUERY_STRING} ^searchword=(.*)
>> RewriteRule ^   q=$1 [NC,L]
>>
>> Ideas for what I'm doing wrong would be greatly appreciated.
> I think something like this is closer:
> RewriteCond %{QUERY_STRING} ^searchword=([^&]+)
> RewriteRule ^ %{REQUEST_URI}?search=%1 [NC,L]
>
> - In the cond, I am dropping everything in the query after the CVE
> value, since Search= and search= would be confusing together.
> - The substitution needs to be the full URL -- using the
> %{REQUEST_URI} variable here
> - Using a ? in the substitution will replace the existing query
> - %1 is the first capture in the preceding condition

This didn't work :-( It found a match, but it doesn't appear to have 
performed the replacement:

Thu Jan 04 16:41:41.144300 2024] [rewrite:trace4] [pid 510782:tid 
510817] mod_rewrite.c(493): [client 68.195.111.42:0] 68.195.111.42 - - 
[webstage.example.com/sid#55795fe93698][rid#7fa7140322c0/initial]
  RewriteCond: input='searchword=CVE-2021-4014&Search=' 
pattern='^searchword=([^&]+)' => matched

It even shows the rewrite:

[Thu Jan 04 16:41:41.144316 2024] [rewrite:trace2] [pid 510782:tid 
510817] mod_rewrite.c(493): [client 68.195.111.42:0] 68.195.111.42 - - 
[webstage.example.com/sid#55795fe93698][rid#7fa7140322c0/initial]
  rewrite '/search' -> '/search?search=CVE-2021-4014'

However, this change is not reflected in the Location bar in my browser.

Maybe I'm missing something? Is there any way to enable logging only for 
the RewriteRule/RewriteCond I'm currently working with, or to otherwise 
be able to more specifically identify the rule I'm testing?

I'm using:

LogLevel info rewrite:trace5

Thanks,
Dave


Re: [users@httpd] Rewrite query string?

Posted by Eric Covener <co...@gmail.com>.
On Thu, Jan 4, 2024 at 2:53 PM Dave Wreski
<dw...@guardiandigital.com.invalid> wrote:
>
> Hi,
>
> I'm trying to replace "searchword" with just "search" in the following URL:
>
> https://example.com/search?searchword=CVE-2021-4014&Search=
>
> I've tried the following RewriteCond/RewriteRule in various forms, but not sure what I'm doing wrong.
>
> RewriteCond %{QUERY_STRING} ^searchword=(.*)
> RewriteRule ^   q=$1 [NC,L]
>
> Ideas for what I'm doing wrong would be greatly appreciated.

I think something like this is closer:
RewriteCond %{QUERY_STRING} ^searchword=([^&]+)
RewriteRule ^ %{REQUEST_URI}?search=%1 [NC,L]

- In the cond, I am dropping everything in the query after the CVE
value, since Search= and search= would be confusing together.
- The substitution needs to be the full URL -- using the
%{REQUEST_URI} variable here
- Using a ? in the substitution will replace the existing query
- %1 is the first capture in the preceding condition



-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Rewrite query string?

Posted by Kristina Nicklas Walters <ju...@hotmail.com>.
My email stay off my email
________________________________
From: Frank Gingras <th...@apache.org>
Sent: Thursday, January 4, 2024 2:03:49 PM
To: users@httpd.apache.org <us...@httpd.apache.org>
Subject: Re: [users@httpd] Rewrite query string?



On Thu, Jan 4, 2024 at 2:53 PM Dave Wreski <dw...@guardiandigital.com.invalid> wrote:

Hi,

I'm trying to replace "searchword" with just "search" in the following URL:

https://example.com/search?searchword=CVE-2021-4014&Search=

I've tried the following RewriteCond/RewriteRule in various forms, but not sure what I'm doing wrong.

RewriteCond %{QUERY_STRING} ^searchword=(.*)
RewriteRule ^   q=$1 [NC,L]

Ideas for what I'm doing wrong would be greatly appreciated.

Thanks,
Dave


Captured values via a RewriteCond are referenced with %1 and not $1.

Either way, I recommend using the rewrite log to see what is actually happening.

Re: [users@httpd] Rewrite query string?

Posted by Frank Gingras <th...@apache.org>.
On Thu, Jan 4, 2024 at 2:53 PM Dave Wreski
<dw...@guardiandigital.com.invalid> wrote:

> Hi,
>
> I'm trying to replace "searchword" with just "search" in the following URL:
>
> https://example.com/search?searchword=CVE-2021-4014&Search=
>
> I've tried the following RewriteCond/RewriteRule in various forms, but not
> sure what I'm doing wrong.
>
> RewriteCond %{QUERY_STRING} ^searchword=(.*)
> RewriteRule ^   q=$1 [NC,L]
>
> Ideas for what I'm doing wrong would be greatly appreciated.
>
> Thanks,
> Dave
>
>
>
Captured values via a RewriteCond are referenced with %1 and not $1.

Either way, I recommend using the rewrite log to see what is actually
happening.