# Setup nginx-include for custom redirect

**URL:** https://discourse.roots.io/t/setup-nginx-include-for-custom-redirect/30043
**Category:** trellis
**Created:** 2025-11-12T16:06:49Z
**Posts:** 3

## Post 1 by @JordanC26 — 2025-11-12T16:06:49Z

Hi,

I have already followed the [Custom Nginx Includes in Trellis | Trellis Docs | Roots](https://roots.io/trellis/docs/nginx-includes/) docs. But maybe I am getting something wrong?

I am trying to setup the following redirects:  
`https://www.mydomain.co.uk/wp/app/uploads/sites/9/`  
to  
`https://www.mydomain.co.uk/app/uploads/sites/11/`

**wordpress\_sites.yml**

```
wordpress_sites:
  nonecom.comfygroup.com:
    site_hosts:
      - canonical: www.mydomain.co.uk
        redirects:
          - mydomain.co.uk
    local_path: ../non-ecom-site
```

I have therefore setup the following file/folder structure:

`/trellis/nginx-includes/www.mydomain.co.uk/media-url-redirects.conf.j2`

And the contents of that `conf` file is:

```
{{ ansible_managed }}

Redirect old Gravity Forms uploads from /sites/9/ to /sites/11/

location ~ ^/app/uploads/sites/9/(.*)$ {
  return 301 /app/uploads/sites/11/$1;
}

Also catch any accidental /wp/app/uploads/ prefix

location ~ ^/wp/app/uploads/sites/9/(.*)$ {
  return 301 /app/uploads/sites/11/$1;
}
```

So far my nginx config/redirects are not being applied to the server at all. Is there any obvious setup issue so far? Thanks.

Notes, my wordpress\_sites file has many more domains, but I have removed for security. This redirect should apply for the [mydomain.co.uk](http://mydomain.co.uk) domain only.

---

## Post 2 by @ben — 2025-11-12T17:06:45Z

Untested — make sure your folder name in `nginx-includes/` matches your `wordpress_sites` name, not the site host:

```
rewrite ^/app/uploads/sites/9/(.*)$ /app/uploads/sites/11/$1 permanent;
rewrite ^/wp/app/uploads/sites/9/(.*)$ /app/uploads/sites/11/$1 permanent;
```

Here’s a real rewrites example from the [roots.io](http://roots.io) site:

```
# @ trellis/nginx-includes/roots.io/rewrites.conf.j2
# (roots.io is the wordpress_sites name)

rewrite ^/plugins/bcrypt-password/$ https://github.com/roots/wp-password-bcrypt permanent;
```

---

## Post 3 by @JordanC26 — 2025-11-13T09:28:51Z

Thanks Ben. Working, I was using a site\_host url instead. Plus I kept provisioning with –nginx tag only but I also needed to do a full provision before even your changes would show up too.
