Properly use NginX rewrite with PHP $_GET["query"], to echo the full URL (incl queries)

35 Views Asked by At

I would like to ECHO the full URL (incl queries) while also using the NginX rewrite (or request_uri, map). I have stire.php file that contains:

$url = htmlspecialchars($_GET["url"]);
echo $url;

In the NginX config I also have:

rewrite ^/stire-(.*)$ /stire.php?url=https://$1;

Visiting /stire.php?url=https://google.com and /stire-google.com I het the same echo:

https://google.com

This is what I am trying to accomplish.

However, if the URL contains queries itself, the ECHO does not write them when when I visit the rewritten URL. For example, /stire.php?url=https://google.com?a=1 will echo correctly:

https://google.com?a=1

...but /stire-google.com?a=1 will only echo:

https://google.com

therefore omitting the query a=1 (or any other following queries).

I've tried using if/request_uri is Nginx config, but ended up in endless loops. To keep this short, I won't write all my failures.

Please advise on what NginX config to use in order to achieve this purpose.

0

There are 0 best solutions below