0

I have setup a server with an "ugly" URL of /search.php?q=query+here that is re-written to a "pretty" URL of /s/query+here.

I have not redirected the ugly URL to the pretty URL yet so you can visit both pages.

The page simply performs echo on $_GET['q'].

Imagine how surprised I was when I saw that the pretty URL displays query+here while the ugly URL displays query here.

They're both exactly the same code/page ... what on earth is going on?

Here is my rewrite... nothing too fancy:

location /s/ {
    rewrite ^/s/(.+)$ /search.php?q=$1 last;
}

The php processor is also behind a reverse proxy if that matters at all? (I don't see how it could, just trying to provide as much info as possible!)

If I create a variable $q and assign the string value what+the and then echo that... both pages display the same what+the.

So it definitely has something to do with the fact that the URL is being rewritten I should think.

  • Something is double encoding your `GET` on the rewrite. PHP auto decodes GETs so the `+` turning into a space is expected from a GET. – user3783243 Jul 14 '23 at 22:51
  • If you think so (and I think you're on the right track), consult the Nginx rewrite module documentation to learn more. Have you tried that? For example it allows to enable logging, then provide the logging information by [edit]ing them in. You should also have the Nginx version in your question. – hakre Jul 14 '23 at 22:56
  • `+` after the `?` is [an early method](https://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20) to encode a space in the query string. If you use `%20` to encode a space you will achieve consistent results before or after the `?`. – Richard Smith Jul 15 '23 at 07:36

0 Answers0