How to rewrite % signs in URLs
27 posts
• Page 1 of 2 • 1, 2
How to rewrite % signs in URLs
Hi,
Can someone please tell me how to rewrite % symbols in URLs. We need to rewrite URLs like this:
/template.asp?price=409.00&width=70%&height=90%
to:
/template.asp?price=409.00&width=70%25&height=90%25
So basically we need to change all %'s to %25 before the page is served.
Thanks,
Mark
Can someone please tell me how to rewrite % symbols in URLs. We need to rewrite URLs like this:
/template.asp?price=409.00&width=70%&height=90%
to:
/template.asp?price=409.00&width=70%25&height=90%25
So basically we need to change all %'s to %25 before the page is served.
Thanks,
Mark
Re: How to rewrite % signs in URLs
Please, does someone have a hint? Tried lots of different things but nothing will match my URLs.
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: How to rewrite % signs in URLs
Hello,
Try something like:
Regards
Andrew
Try something like:
- Code: Select all
RewriteEngine on
RewritreBase /
RewriteCond %{QUERY_STRING} ^price=409\.00&width=70\%&height=90\%$
RewriteRule ^template\.asp /template.asp?price=409.00&width=70\%25&height=90\%25? [NC,R=301,L]
Regards
Andrew
Re: How to rewrite % signs in URLs
Hi Andrew, thank you for the reply.
The issue I have is that I have lots of these URLs, so I need to remove all the %'s and replace them with %25. How can I do that?
The issue I have is that I have lots of these URLs, so I need to remove all the %'s and replace them with %25. How can I do that?
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: How to rewrite % signs in URLs
are they all with template.asp? are all '%' located in querystring?
Regards
Andrew
Regards
Andrew
Re: How to rewrite % signs in URLs
Andrew, they are in various folders and templates, not just template.asp. The % are only in the CGI params (in querystring).
Regards,
Mark
Regards,
Mark
Re: How to rewrite % signs in URLs
Andrew, is it possible to just change %'s in the query string only, and change them to some other string?
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: How to rewrite % signs in URLs
You should be able to do it using loop-rule. It's [LP] flag.
Regards
Andrew
- Code: Select all
RewriteEngine on
RewritreBase /
RewriteCond %{QUERY_STRING} ^([^\%]+)\%(&.*)$
RewriteRule ^(.*) /$1?%1\%25%2? [NC,LP,R=301,L]
Regards
Andrew
Re: How to rewrite % signs in URLs
Hi Andrew, that rewrite just results in a 404 error for a URL such as:
http://www.mydomain.com/somefolder/some ... e&width=70%&height=90%
I need this URL to become:
http://www.mydomain.com/somefolder/some ... ight=90%25
Seems simple, but isn't
http://www.mydomain.com/somefolder/some ... e&width=70%&height=90%
I need this URL to become:
http://www.mydomain.com/somefolder/some ... ight=90%25
Seems simple, but isn't
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: How to rewrite % signs in URLs
Well, it results in 404, but are there any changes in the URL? did redirect occur? or it didn't occur at all?
Re: How to rewrite % signs in URLs
Ok, the URL comes back as:
http://www.mydomain.com//test1/test2/te ... ight=90%25
So rewriting is taking place, resulting in a 404. Getting two slashes after the domain and the first CGI argument has been removed. It should be:
http://www.mydomain.com/test1/test2/tes ... ight=90%25
http://www.mydomain.com//test1/test2/te ... ight=90%25
So rewriting is taking place, resulting in a 404. Getting two slashes after the domain and the first CGI argument has been removed. It should be:
http://www.mydomain.com/test1/test2/tes ... ight=90%25
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: How to rewrite % signs in URLs
So it does work... just not the way we want...
Lets try this, and see what'll happen
Lets try this, and see what'll happen
- Code: Select all
RewriteCond %{QUERY_STRING} ^([^\%]+)\%(&.*)$
RewriteRule ^(.*) $1\?%1\%25%2? [NC,LP,R=301,L]
Re: How to rewrite % signs in URLs
Andrew, that is better thanks...
Now I get my URL rewritten
http://www.mydomain.com/test/test2/test ... ight=90%25
For some reason the first % argument is converted to %2525, whilst the second just %25. The latter is correct, the former is not.
In Internet Explorer 9 the URL will not load and gives a 404 when the redirect occurs btw. The rewrite works in Chrome and FireFox, but not in MSIE. Most of our visitors are using MSIE
Thanks,
Mark
Now I get my URL rewritten
http://www.mydomain.com/test/test2/test ... ight=90%25
For some reason the first % argument is converted to %2525, whilst the second just %25. The latter is correct, the former is not.
In Internet Explorer 9 the URL will not load and gives a 404 when the redirect occurs btw. The rewrite works in Chrome and FireFox, but not in MSIE. Most of our visitors are using MSIE
Thanks,
Mark
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: How to rewrite % signs in URLs
Well... I'd think it's escaping, but it happens only to one part...
So my assumption would be that this issue occurs when th rules runs the second time. Can you confirm? Try to request a URL with only one '%'.
Regards
Andrew
So my assumption would be that this issue occurs when th rules runs the second time. Can you confirm? Try to request a URL with only one '%'.
Regards
Andrew
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: How to rewrite % signs in URLs
...and browsers. We're doing the server side redirects. Which means that sever treats everyone just the same. So the problem is in broser(caching, headers, handling responses, etc). There's nothing we can do here.
Re: How to rewrite % signs in URLs
Hi, yes it is ok with one parameter, as you say.
If MSIE does not work and Chrome/FireFox/Safari/Opera/Silk does, why is that? I wonder why IE does not like the resulting 301'd URL?
If MSIE does not work and Chrome/FireFox/Safari/Opera/Silk does, why is that? I wonder why IE does not like the resulting 301'd URL?
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: How to rewrite % signs in URLs
Hm......
LEts try:
LEts try:
- Code: Select all
RewriteCond %{QUERY_STRING} ^([^\%&]+)\%(&.*)$
RewriteRule ^(.*) $1\?%1\%25%2? [NC,LP,R=301,L]
Re: How to rewrite % signs in URLs
That doesn't seem to do anything, the same URL comes back unchanged (all browsers).
Have we, gasp, found something that Rewriter 3.0 cannot do!? Surely not
Have we, gasp, found something that Rewriter 3.0 cannot do!? Surely not
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: How to rewrite % signs in URLs
Don't call me Surely! (sorry, couldn't resist. It's the joke in the office when someone starts sentence with "Surely, ..")
Well, I just don't get it.It should work. What we do - we divide querystring into 2 parts based on the condition that it meets "%&" and if it does, we take the firsat part of querystring + add "%25&" instead of "%" + second part. And it all goes in a loop, untill no "%&" is found
I just don't understand why when it runs the second time, it take "%25&" and transforms it again...
EUREKA! It seems like there's something related to the escaping the characters. Try to use [NE] flag in this rule.
Regards
Andrew
Well, I just don't get it.It should work. What we do - we divide querystring into 2 parts based on the condition that it meets "%&" and if it does, we take the firsat part of querystring + add "%25&" instead of "%" + second part. And it all goes in a loop, untill no "%&" is found
I just don't understand why when it runs the second time, it take "%25&" and transforms it again...
EUREKA! It seems like there's something related to the escaping the characters. Try to use [NE] flag in this rule.
Regards
Andrew
Re: How to rewrite % signs in URLs
Tried replacing NC with NE and same result - same URL comes back. Here's the URL I request, and the same comes back:
The rules I used:
Is that use of NE correct? No %25's are placed in the URL at all now, indeed it does not seem if the URL is now rewriting at all
- Code: Select all
http://www.mydomain.com/test/test2/test.asp?price=100.00&mode=true&width=70%&height=90%
The rules I used:
- Code: Select all
RewriteCond %{QUERY_STRING} ^([^\%&]+)\%(&.*)$
RewriteRule ^(.*) $1\?%1\%25%2? [NE,LP,R=301,L]
Is that use of NE correct? No %25's are placed in the URL at all now, indeed it does not seem if the URL is now rewriting at all
27 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 14 guests