Forum Moderators: phranque

Message Too Old, No Replies

rewrite and url decoding

         

marciano

8:22 pm on Dec 14, 2011 (gmt 0)

10+ Year Member



It seems a site is linking to mine in a bad way. From google webmaster tools I see some 404 errors

domain.com/file.php?id=1 (404) Not found (Date)

This url works ok but because of browser page decoding, the real (404) url is

domain.com/file.php%3Fid%3D1 (this is what my browser displays in the url input when I click on google url)
It is confusing what is real and what is en/decoded.

My first try was
[size=3]RewriteRule ^(.*)\%3F(.*)$ $1?$2 [R=301, L] [/size]
to change %3F to '?' but it does not work.

[size=3]RewriteCond %{QUERY_STRING} ^id\%3D(.+) 
RewriteRule ^(.*)$ $1?id=%1 [R=301,L] [/size]

does change %3D to '=' for file.php?id%3D1
Thank you

lucy24

10:03 pm on Dec 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month


Have you now figured out that the \[size\] statement doesn't work in the Forums? :)

I think you may be looking for the \[B\] flag:

http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_b

Just to confuse us, they say "escape" where you and I would say "encode" (because "escape" means RegEx backslash-escapes), and B is for "back-reference". Well, duh.

See if you can get that to work.

... and speaking of escape, I had to throw in a bunch of superfluous backslashes just to get this ### thing to post, even when I said clearly "disable [codes] for this message". Hmph. DO NOT USE THE BACKSLASH in your actual code.

Edit: Oh my gosh. I never knew how they did that. If you disable codes, the post also displays in your browser's default font instead of the forums' chosen sans-serif. WooHoo, I have learned something.

marciano

10:30 pm on Dec 14, 2011 (gmt 0)

10+ Year Member



Thanks for your answer Lucy, I had tried without backslashes and results were the same.

RewriteRule ^(.*)%3F(.*)$ $1?$2 [R=301, L]

lucy24

11:42 pm on Dec 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oops, no, I didn't mean try it without escapes. I meant that you have to omit the backslashes from my post because the Forums didn't like my reference to #flag_b [httpd.apache.org]. The software thinks it's boldface markup :) Good thing there is no html <f> format or the Apache forum would never get anywhere.

marciano

11:51 pm on Dec 14, 2011 (gmt 0)

10+ Year Member



[ B ] flag makes %3F and %3D not to be decoded, letīs say transformed to '?' and '='
I donīt want this.
Something happens with
RewriteRule ^(.*)%3F(.*)%3D(.*)$ $1?$2=$3 [R=301, L]
that does not 'transform'
domain.com/file.php%3Fid%3D1 to domain.com/file.php?id=1

Just to test I removed all '%' (in redirect and url browser input) and redirect work as expected

And as I said in my first post
RewriteCond %{QUERY_STRING} ^id\%3D(.+)
RewriteRule ^(.*)$ $1?id=%1 [R=301,L]

does 'change' %3D to '=' for file.php?id%3D1
Thank you