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/;
...
Human Logic, AI Syntax... Note on Content: I'm a Systems Engineer, not a native English writer. To ensure my technical ideas are clear and accessible, I use AI tools to polish the grammar and style. The workflow is simple: I provide the logic, the code, and the real-world experience. The AI handles the "English-to-Human" translation layer. If you find a bug, that's on me. If you find a perfectly placed comma, that's probably the AI.

Comments

Popular posts from this blog

FreeRadius with Google Workspace LDAP

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