Hello, dear! It is necessary to redirect view requests

Osite.ru/anything.php?sub=anything 

on

 so.kr/index.php?url=http://site.ru/anything.php?sub=anything 

(for further work with the received url).

The main problem in the required URL is the possible presence of two question marks. Mod_rewrite, naturally handles only the first. For example:

 RewriteCond %{HTTP_HOST} ^(.*)osite\.ru$ [NC] RewriteRule ^(.*)$ http://so.kr/index.php?url=http://%1site.ru$1 [R=301,L,QSA] 

Seeing that the "?" Sign is already present in the URL, mod_rewrite replaces the second question mark with "&". That is, the URL

 Osite.ru/anything.php?sub=anything 

redirects to

 so.kr/index.php?url=http://site.ru/anything.php&sub=anything 

and it is necessary, as I said, on:

 so.kr/index.php?url=http://site.ru/anything.php?sub=anything 

Tell me, please, is it possible to solve the problem using mod_rewrite?

Thanks in advance for any hints!

    1 answer 1

    As an option, do it like this (i.e., instead of the QSA flag, we explicitly add a query string to the resulting address):

     RewriteCond %{HTTP_HOST} ^(.*)osite\.ru$ [NC] RewriteRule ^(.*)$ http://so.kr/index.php?url=http://%1site.ru$1?%{QUERY_STRING} [R=301,L] 

    PS Yes, this second question is encoded in % 3f , but this is correct .

    UPD For aesthetics:

     RewriteCond %{QUERY_STRING} ^$ RewriteCond %{HTTP_HOST} ^(.*)osite\.ru$ [NC] RewriteRule ^(.*)$ http://so.kr/index.php?url=http://%1site.ru$1 [R=301,L] RewriteCond %{HTTP_HOST} ^(.*)osite\.ru$ [NC] RewriteRule ^(.*)$ http://so.kr/index.php?url=http://%1site.ru$1?%{QUERY_STRING} [R=301,L] 
    • Thanks for the answer, but I forgot to mention that the variables in the URL may be different, and may not be at all. And in your case, even if it just happens on osite.ru, will it redirect it to so.kr/index.php?url=http://site.ru ? It may not care, of course, but not aesthetically pleasing. Yes, and a crutch. What glitches can lead to. - seventh
    • Aesthetics added, and glitches should not be any ending with a question. - Visman