问题
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)
My first try was
RewriteRule ^(.*)\%3F(.*)$ $1?$2 [R=301, L]
to change %3F
to '?
' but it does not work. It is confusing what is real and what is en/decoded.
Thanks
回答1:
Hmm, try this:
RewriteRule ^(.*\%3F.*)\%26([^%]*)(\%3D)?(.*)$ $1&$2=$4 [N]
RewriteRule ^(.*)\%3F([^%]*)(\%3D)?(.*)$ $1?$2=$4 [R=301,L]
EDIT: I see you already tested for %3F... if that didn`t work, then something else might be up.
回答2:
It is not an elegant solution, but after months, it is the only way I found.
Regular case
domain.tld/dir/file.php?id=UID&qty=NUM&... (from old site structure)
is rewritten as
domain.tld/newfile.php?id=UID&qty=NUM&... [R=301,L]
So, for requests like
domain.tld/dir/file.php%3Fid%3DUID%26qty=NUM%26... (from old site structure)
I perform
RewriteRule ^dir/file\.php(.*)$ script.php?qs=$1 [R,L]
This MUST be AFTER all directives that involves dir/file.php
Then I can handle the query string $_GET['qs'] in script.php
It may not apply to other situations that would enter into a loop or undesired results.
回答3:
use [NE] flag in your RewriteRule
来源:https://stackoverflow.com/questions/8464298/rewrite-and-url-decoding