2

I want to map

https://www.example.com/Something/SomethingElse/

to

https://www.example.com/index.php?/Something/SomethingElse/

So far I understood that I need the location directive in nginx and use the try_files inside, something like this:

location ~ *???* {
  try_files $uri $uri/ /index.php?$1;
}

Now, the question is: how do I write the regular expression *???* to split URL, so I get the /Something/SomethingElse/ back (into $1)? Is it possible?

Perhaps, there is an easier way? nginx variable?

1 Answers1

1

The variable $request_uri that contains all parts of URL excluding the host (and the scheme - http or https). So, the solution is to use the following code (or something similar)...

location / {
   try_files $uri $uri/ /index.php?$request_uri
}

We have a similar variable in Nginx named $uri. It is not recommended to use it as it can change its value during the run time.

Pothi Kalimuthu
  • 6,117
  • 2
  • 26
  • 38