Roots Discourse

Trellis Nginx Redirect

Client would like his single site Trellis based WordPress site at DO to not show / remove author/* and not have any author pages show in search results. They are not using the information now anyways. Also, due to the way the current theme is set up (blog part ignored) the wrong information is shown now anyways as all blog templates are used to display custom post data.

I was wondering how I could best add a redirect to Nginx to send all people and search engines that wind up at https://domain.com at home . This seems like the quickest solution. So how can I add:

if ( $request_filename ~ old-page/  ) {
       rewrite ^ http://domain.com/new-page/? permanent;
   }

NB Source

to the Trellis Nginx conf the best way? Should I create a child template as mentioned in the Roots Trellis documentation here? I understood it has to be added to the main server block. So should I use a block like:

{% extends 'roles/nginx/templates/nginx.conf.j2' %}

{% block http_begin -%}
  server_names_hash_bucket_size 128;
  server_names_hash_max_size 512;
{% endblock %}

Two, do you think this is the best way or is there another better one? I was also considering some sort of PHP redirect or using the code from the no longer really well maintained hide author plugin , but the first option seems cleaner to me…

Well, in the end I used a wp_redirect in the author.php template:
<?php wp_redirect( 'https://domain.com', 301 ); exit; ?>
Not as clean as an Nginx redirect perhaps, but this seems to work as well.

I often use the Redirection plugin for this.

1 Like