Welcome! Log In Create A New Profile

Advanced

Re: rewriting $arg into request.

Francis Daly
January 31, 2020 06:30AM
On Fri, Jan 31, 2020 at 01:13:30AM +0000, Steve Wilson wrote:

Hi there,

> Currently wordpress is using ugly urls for posts, so "/?p=1234" in wordpress
> might be "/this_nice_title" in hugo.
> Now hugo allows me to specify aliases too which I'd like to leverage to
> maintain links, but this is where I seem to be struggling with rewrite/map
> etc.
>
> Am I missing a way to access the arguments?

Without knowing how hugo works, I would suggest ignoring its "alias"
feature for this, and just letting nginx invite the client that requests
"old", to instead request "new".

Assuming that you have the list of old-and-new urls that you care about,
and that the old urls are unique case-insensitively, then using a "map"
reading "$request_uri" (old) and writing, say, "$hugo_url" (new), would
probably be the simplest.

map $request_uri $hugo_url {
/?p=1234 /this_nice_title;
}

in http{} (add more lines as wanted), along with something like

if ($hugo_url) { return 301 $hugo_url; }

in the correct server{}, should work, I think. (Untested by me!)

(Maybe change the "return" line to include "https://this-server$hugo_url",
if you want that.)

(If all of your "old" requests have the same content from the first /
to the ?, then you could choose to isolate the "if" within the matching
"location = /" block for efficiency; there may be extra config needed
in that case.)

http://nginx.org/r/map
http://nginx.org/r/$request_uri

Good luck with it,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

rewriting $arg into request.

Steve Wilson January 30, 2020 08:14PM

Re: rewriting $arg into request.

Francis Daly January 31, 2020 06:30AM

Re: rewriting $arg into request.

Steve Wilson January 31, 2020 07:12AM

RE: rewriting $arg into request.

Reinis Rozitis January 31, 2020 07:38AM

Re: rewriting $arg into request.

Steve Wilson January 31, 2020 05:00PM

Re: rewriting $arg into request.

Francis Daly January 31, 2020 08:00AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 74
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready