Welcome! Log In Create A New Profile

Advanced

Re: Best practice for URL rewriting with php parameter

Francis Daly
November 11, 2015 02:40PM
On Wed, Nov 11, 2015 at 06:50:54PM +0000, Mik J wrote:

Hi there,

> I tried both methods but none of them worked. I'm going to look at it more in details (and display the php logs because I just had a blank page).

First configure things so that an explicit request for
/index.php?x=information gives you the response that you want.

Keep it simple, do one thing at a time.

> Also I would like to know why the solution you're offering is a "best practice" ?At first it seems a bit heavy because I'll have a paragraph like that for every x variable (x=information, x=something).

The original question did not have multiple x variables. A different
question probably gets a different answer.

Using "rewrite" instead of "try_files" should have exactly the same
number of location{} blocks.

And it avoids a presumed-unnecessary filesystem check -- what should
happen if the file /usr/local/nginx/htmlinformation exists on your
filesystem?

Using "fastcgi_pass" and friends instead of "rewrite" should also have
exactly the same number of location{} blocks. And it means that nginx
can skip one step of processing -- if the rewrite was going to go to a
location which does exactly this anyway.

It does mean that there are more words involved; but if the number of
location{} block is going to be big, you are probably going to generate
them anyway.

> Considering also that the users URL might not look like the x variable.nginx.org/info_1234 is an internal rewrite of index.php?x=information

I don't see the difference this makes, in the three cases in question.

In each case you have the request, and a different string as the x= value.

If you choose to use variables in a common location, or something like
that, then you will still need the mapping or request to x= value. If you
knew that the mapping is always "remove the first /", then you wouldn't
need a separate table. But you don't have that now, either.


> I tried two other solutions that workedrewrite /info_1234 /index.php?x=information;
> and
> location = /info_1234 { try_files info_1234 /index.php?x=information; }
> I would like to understand why your solution is better than these, why is it a best practice ?

It means that nginx has less work to do to process the request.

Sometime that is not the thing that you want to optimise for.

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Best practice for URL rewriting with php parameter

miky November 11, 2015 08:16AM

Re: Best practice for URL rewriting with php parameter

Francis Daly November 11, 2015 08:56AM

Re: Best practice for URL rewriting with php parameter

miky November 11, 2015 09:32AM

Re: Best practice for URL rewriting with php parameter

Francis Daly November 11, 2015 10:48AM

Re: Best practice for URL rewriting with php parameter

miky November 11, 2015 01:56PM

Re: Best practice for URL rewriting with php parameter

Francis Daly November 11, 2015 02:40PM

Re: Best practice for URL rewriting with php parameter

miky November 12, 2015 06:06PM

Re: Best practice for URL rewriting with php parameter

Francis Daly November 15, 2015 07:28AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 147
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready