RewriteRule question mark escape
7 posts
• Page 1 of 1
RewriteRule question mark escape
Hi,
Does a question mark in RewriteRule need to be escaped? It seems so.
This started as a problem trying to remove one querystring parameter, and leave the rest, and redirect. (This is a small piece of a bigger problem; I found questions on stackoverflow, but no answer yet.)
rewrite
/something/?x=abc&y=def
to
/something/abc/?y=def
To simplify, let's say x parameter is always first, and there are always additional parameters.
I have this:
The problem is I get the entire querystring, instead of just portion in the %2 group:
/something/abc/?x=abc&y=def
After trying several things, I found if I escape the question mark, then it "knows" it has a querystring, and won't append the original:
This works:
Thank you,
Bob
Does a question mark in RewriteRule need to be escaped? It seems so.
This started as a problem trying to remove one querystring parameter, and leave the rest, and redirect. (This is a small piece of a bigger problem; I found questions on stackoverflow, but no answer yet.)
rewrite
/something/?x=abc&y=def
to
/something/abc/?y=def
To simplify, let's say x parameter is always first, and there are always additional parameters.
I have this:
- Code: Select all
# Starts with x=, non-ampersand, ampersand, remaining required.
RewriteCond %{QUERY_STRING} ^x=([^&]+)&(.+)
RewriteRule ^/something/$ /something/%1/?%2 [NC,R=301,L]
The problem is I get the entire querystring, instead of just portion in the %2 group:
/something/abc/?x=abc&y=def
After trying several things, I found if I escape the question mark, then it "knows" it has a querystring, and won't append the original:
This works:
- Code: Select all
# Starts with x=, non-ampersand, ampersand, remaining required.
RewriteCond %{QUERY_STRING} ^x=([^&]+)&(.+)
RewriteRule ^/something/$ /something/%1/\?%2 [NC,R=301,L]
Thank you,
Bob
Re: RewriteRule question mark escape
To clarify, my question is:
Does a question mark in RewriteRule Substitution need to be escaped?
Thanks,
Bob
Does a question mark in RewriteRule Substitution need to be escaped?
Thanks,
Bob
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: RewriteRule question mark escape
Hello,
In your particular case - yes, it's etter to escape it.
In general, to avoid appending original query string you need to end the rule with '?' like 'RewriteRule a /b? [NC,L]'
Regards
Andrew
In your particular case - yes, it's etter to escape it.
In general, to avoid appending original query string you need to end the rule with '?' like 'RewriteRule a /b? [NC,L]'
Regards
Andrew
Re: RewriteRule question mark escape
Hi,
Thanks for the reply. To clarify though, I'm not trying to suppress the entire querystring. In fact, if I put the ? on the end, it removes all querystring parameters, even the ones I put in manually.
The question is how to put in my own querystring parameters, and have it omit the originals.
This removes all:
RewriteRule a /b? [NC,L]
This includes them all (even though I only want 'x')
RewriteRule a /b?x=123 [NC,L]
This works as I expected, including 'x' and no others.
RewriteRule a /b\?x=123 [NC,L]
The question is to confirm whether I MUST always escape the question mark, not just that it's better to. Or, is this a bug that needs a fix, if you don't mean to require it?
Thanks,
Bob
Thanks for the reply. To clarify though, I'm not trying to suppress the entire querystring. In fact, if I put the ? on the end, it removes all querystring parameters, even the ones I put in manually.
The question is how to put in my own querystring parameters, and have it omit the originals.
This removes all:
RewriteRule a /b? [NC,L]
This includes them all (even though I only want 'x')
RewriteRule a /b?x=123 [NC,L]
This works as I expected, including 'x' and no others.
RewriteRule a /b\?x=123 [NC,L]
The question is to confirm whether I MUST always escape the question mark, not just that it's better to. Or, is this a bug that needs a fix, if you don't mean to require it?
Thanks,
Bob
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: RewriteRule question mark escape
Question mark is a symbol used in regular expression and has meaning behind it. However, usually it doesn't require any escaping. I don't use escaping.
Here are some correction to your examples:
Regards
Andrew
Here are some correction to your examples:
- Code: Select all
This removes any querystring:
RewriteRule a /b? [NC,L]
Add X parameter to B and appends the original querystring from A
RewriteRule a /b?x=123 [NC,L]
Add X parameter to B and DOESN'T append the original querystring from A
RewriteRule a /b?x=123? [NC,L]
Regards
Andrew
Re: RewriteRule question mark escape
This is good to track down. When I do the third one, as shown without escaping it:
It removes the both the X parameter and the original querystring, producing just /b
I'm using version 0105, but I believe I saw this also on 0084 (the previous one I was using).
Thanks,
Bob
- Code: Select all
Add X parameter to B and DOESN'T append the original querystring from A
RewriteRule a /b?x=123? [NC,L]
It removes the both the X parameter and the original querystring, producing just /b
I'm using version 0105, but I believe I saw this also on 0084 (the previous one I was using).
Thanks,
Bob
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: RewriteRule question mark escape
I'll look into it. thanks
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests