Best practice for URL rewriting with php parameter

Francis Daly francis at daoine.org
Wed Nov 11 13:55:00 UTC 2015


On Wed, Nov 11, 2015 at 01:14:31PM +0000, Mik J wrote:

Hi there,

> I have checked many ways to implement what I want (including if is evil) and I've been able to reach what I wanted to do (something simple)
> I want that a user who accessesnginx.org/informationwill be redirected in the background tonginx/index.php?x=informationSo that my index.php page is dymanic

What does "redirected in the background" mean?

I suspect it refers to an nginx internal rewrite, rather than to a
http redirect.

> I did like this in my virtual host configurationlocation /information { try_files information /index.php?x=information; }
> I would like to know if:a) This is the best practice to do what I would like to do ?

I'd say "no".

I'm not fully sure what it is that you want to do, but I suspect that
"rewrite" (http://nginx.org/r/rewrite) may be what you want; unless
you will describe how /index.php is intended to be handled -- in which
case just using (e.g.) fastcgi_pass with some suitable fastcgi_param
directives might be even better.

> b) If "location /information" is an exact match only. Apparently no because nginx.org/informationxxxsomethingxxxweird also matches

It is not an exact match.

http://nginx.org/r/location

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list