Rewrite and decrypt URLs

The site seems to be poorly connected with mine. From Google’s webmaster tools, I see about 404 errors

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

This url is working fine, but due to the decoding of the browser page, the real (404) URL

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

My first attempt was

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

to change %3F to ' ? 'but that won't work. This confuses what is real and what is en / decoded.

thanks

+2
source share
3 answers

This is not an elegant solution, but after a few months it is the only way to find it.

Ordinary case

 domain.tld/dir/file.php?id=UID&qty=NUM&... (from old site structure) 

corresponded as

 domain.tld/newfile.php?id=UID&qty=NUM&... [R=301,L] 

So for queries like

 domain.tld/dir/file.php%3Fid%3DUID%26qty=NUM%26... (from old site structure) 

Doing

 RewriteRule ^dir/file\.php(.*)$ script.php?qs=$1 [R,L] 

This MUST AFTER all directives related to dir / file.php

Then I can process the query string $ _GET ['qs'] in script.php

It may not apply to other situations that enter into a cycle or unwanted results.

0
source

Hmm, try the following:

 RewriteRule ^(.*\%3F.*)\%26([^%]*)(\%3D)?(.*)$ $1&$2=$4 [N] RewriteRule ^(.*)\%3F([^%]*)(\%3D)?(.*)$ $1?$2=$4 [R=301,L] 

EDIT: I see that you already tried% 3F ... if that didn't work, then something else is possible.

0
source

use the [NE] flag in the RewriteRule

0
source

Source: https://habr.com/ru/post/896230/


All Articles