• Greetings,

    Your plugin is great and well done. I have several very high traffic news sites that I work on, each with many redirects (for various user reasons). However, for performance reasons, I’d like to pass the redirection to Nginx rather than WordPress. I’d like to be able to be able to write to a file (for example /.redirects.nginx, or whatever – name is not important) in webroot, similar to how you write a .htaccess file for Apache.

    I was wondering what the easiest way to do this with your plugin is. I imagine that I can do something like including models/file-io.php and using the Red_FileIO class, but I was wondering if there was a better way. I tried hitting the /wp-json/redirection/v1/export/all/nginx/ endpoint to get it, but I always get a “rest_forbidden” error when a _wpnonce isn’t passed. Ideally, the plugin would write it automatically like it does for .htaccess, but alternatively, I can trigger the write myself (I’d also want to filter out the server{ ... } block wrap and just have the redirect lines for including in existing nginx server block, however, simply writing the file would be fine as I can filter that out with a script either way). Just looking for ideas on how to do it in a way that is somewhat future proof (ie, reduced possibility of breaking after future updates).

    In short, I’d like to get the content of what this button outputs:
    Redirection export Nginx

    …and save it to a file (such as /.redirects.nginx or whatev), and then include it in the site’s main nginx.conf.

    Step two, of course, would be for me to devise a way to gracefully and safely reload Nginx when the file is changed if there is no error – nginx -t && nginx -s reload, but I’ll figure that part out myself.

    tl;dr – What is the best way to capture/output the redirect rules in nginx syntax?

    
    # Created by Redirection
    # Fri, 14 Feb 2020 01:23:45 +0000
    # Redirection 4.6.2 - https://redirection.me
    
    #server {
        rewrite (?i)^/old-category/(.*)$ /new-hotness/$1 permanent;
        rewrite (?i)^/test-123$ /whatever/path permanent;
        rewrite (?i)^/news/2020/01/10/greedo-shot-first$ /news/2020/01/10/han-shot-first permanent;
        rewrite (?i)^/news/2020/01/10/greedo-shot-first/amp$ /news/2020/01/10/han-shot-first/amp permanent;
        # ...etc
    #}
    
    # End of Redirection
    

    Thank you in advance,
    Daniel

    • This topic was modified 4 years, 10 months ago by Daniel Hendricks. Reason: Try to fix code block
    • This topic was modified 4 years, 10 months ago by Daniel Hendricks.
    • This topic was modified 4 years, 10 months ago by Daniel Hendricks.
    • This topic was modified 4 years, 10 months ago by t-p.
Viewing 1 replies (of 1 total)
  • Plugin Author John Godley

    (@johnny5)

    Nginx rules are not automatically written because of the additional complexity of how rules are defined in Nginx – it is not as straightforward as dropping a .htaccess file somewhere.

    You can use the REST API. You will need to form a proper authenticated request, either by passing authentication details or using rest_do_request to internally call the API. This is not really a Redirection question, but a general REST API one.

    https://redirection.me/developer/rest-api/

    You could also use WP CLI:

    https://redirection.me/developer/wp-cli/

Viewing 1 replies (of 1 total)
  • The topic ‘Easiest way to save nginx conf on event (similar to .htaccess)’ is closed to new replies.