Moving WordPress redirects to nginx

We have pretty cool json from WordPress redirect table and we need move this action to nginx.

[
  {
    "id": 834,
    "created_at": "2018-08-02 11:41:56",
    "updated_at": "2018-08-02 11:41:56",
    "deleted_at": null,
    "path": "(?i)^(\\/[a-z]{2})?\\/affiliate-landing\\/?(\\?([\\w-]+(=[\\w-]*)?(&[\\w-]+(=[\\w-]*)?)*))?$",
    "url": "/affiliate/$2",
    "domain": "domain.com"
  },
  {
    "id": 837,
    "created_at": "2018-08-02 11:41:56",
    "updated_at": "2018-08-02 11:41:56",
    "deleted_at": null,
    "path": "\\/lt\\/?(\\?([\\w-]+(=[\\w-]*)?(&[\\w-]+(=[\\w-]*)?)*))?$",
    "url": "/$2",
    "domain": "domain.com"
  },
  {
    "id": 840,
    "created_at": "2018-08-02 11:41:56",
    "updated_at": "2018-08-02 11:41:56",
    "deleted_at": null,
    "path": "(?i)^(\\/[a-z]{2})?\\/proxy\\/?(\\?([\\w-]+(=[\\w-]*)?(&[\\w-]+(=[\\w-]*)?)*))?$",
    "url": "/web-proxy/",
    "domain": "domain.com"
  },
...
]

jq can help us easy convert it to nginx map file.
$ curl -s -X GET https://domain.com/wp-export-api.json | jq -r '.[] | with_entries(select(.key == ("url","path"))) | "~\(.path)\t\(.url);"'
~(?i)^(\/[a-z]{2})?\/affiliate-landing\/?(\?([\w-]+(=[\w-]*)?(&[\w-]+(=[\w-]*)?)*))?$   /affiliate/$2;
~\/lt\/?(\?([\w-]+(=[\w-]*)?(&[\w-]+(=[\w-]*)?)*))?$    /$2;
~(?i)^(\/[a-z]{2})?\/proxy\/?(\?([\w-]+(=[\w-]*)?(&[\w-]+(=[\w-]*)?)*))?$       /web-proxy/;
...

Comments

Popular posts from this blog

FreeRadius and Google Workspace LDAP

pssh (parallel-ssh) problems on Debian 10 with Python 3.7