# Rewrite XML sitemaps w/ Nginx includes

**URL:** https://discourse.roots.io/t/rewrite-xml-sitemaps-w-nginx-includes/10546
**Category:** trellis
**Tags:** nginx
**Created:** 2017-09-29T10:28:18Z
**Posts:** 9

## Post 1 by @Henk — 2017-09-29T10:28:18Z

I’m using the [Google XML Sitemaps](https://wordpress.org/plugins/google-sitemap-generator/) plugin. I added the following file to my Trellis project: `\nginx-includes\<site_name>\rewrites.conf.j2`, and configured the following rewrite rules - as suggested by [Arne Brachold](https://wordpress.org/support/topic/40-is-broken-in-fpmfastcgi-servers/#post-5401665):

```
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;
```

However, I still get 404’s. It does work for [roots.io/sitemap.xml](https://roots.io/sitemap.xml). What am I missing here? Thanks in advance!

---

## Post 2 by @Henk — 2017-09-29T18:39:36Z

In addition. The file is not templated to the remote’s `/etc/nginx/includes.d/<site_name>/` directory. When manually copied, the `rewrites.conf` gets deleted. So, that means the file lacks a corresponding template in my local machine’s `nginx-includes`. Meaning that `\nginx-includes\<site_name>\rewrites.conf.j2` is not correct. But, what should it be then? Please your help.

---

## Post 3 by @fullyint — 2017-09-29T23:54:44Z

> [@Henk](#):
>
> Meaning that `\nginx-includes\<site_name>\rewrites.conf.j2` is not correct. But, what should it be then?

Does `<site_name>` in your path match the [site key](https://github.com/roots/trellis/blob/4a2a70af503674f4c8d5a42edf4093d14d89f7b0/group_vars/production/wordpress_sites.yml#L6) exactly? It wouldn’t work if it matches one of the [`site_hosts`](https://github.com/roots/trellis/blob/4a2a70af503674f4c8d5a42edf4093d14d89f7b0/group_vars/production/wordpress_sites.yml#L8-L10), unless they too match the site key exactly. It would be easiest to help if you post your `wordpress_sites` exactly and nginx-includes path, using the real site key instead of obscuring with “`site_name`.”

Could you help us understand what version of Trellis you are using? You could post the topmost entry in your [`CHANGELOG.md`](https://github.com/roots/trellis/blob/4a2a70af503674f4c8d5a42edf4093d14d89f7b0/CHANGELOG.md). For example, if you are using a version older than [Dec 1, 2016](https://github.com/roots/trellis/pull/687), the `nginx-includes` path will not work (e.g., see [docs diff](https://github.com/roots/docs/commit/f03afc956e72b70f418e6b080de7bb512a3fde7c#diff-5c6d93ee9606406b58fb004d5653f215L28) for where includes were before).

---

## Post 4 by @Henk — 2017-09-30T10:49:16Z

Thanks for your help, Phill. I’m using Trellis version 1.0.0-rc.1

Top part of my wordpress\_sites.yml:

```
# group_vars/staging/wordpress_sites.yml
wordpress_sites:
  ventizo.com:
    site_hosts:
      - canonical: staging.ventizo.com
```

Exact location of my `rewrites.conf.j2`: `/nginx-includes/ventizo.com/rewrites.conf.j2`. The `nginx-includes` folder is on the same level as `site` and `trellis`.

I re-ran the provision playbook with and without `--tags nginx-includes` - with the same NOK effect.

---

## Post 5 by @Henk — 2017-09-30T11:09:13Z

Note that, I’m running my development environment on Windows 10 Pro. So, Ansible runs on the VM. I don’t know if that’s significant?

---

## Post 6 by @fullyint — 2017-09-30T18:23:22Z

@Henk, thanks for posting the various info. That helps rule out certain issues.

> [@Henk](#):
>
> The `nginx-includes` folder is on the same level as `site` and `trellis`.

Could you try moving the `nginx-includes` dir into your `trellis` dir? If that works (and we know that it isn’t perhaps an issue exclusive to Windows hosts), I’ll update the [nginx-includes docs](https://roots.io/trellis/docs/nginx-includes/#include-files) to clarify this placement.

```
example.com
├── site
└── trellis
    └── nginx-includes
```

---

## Post 7 by @Henk — 2017-09-30T19:15:42Z

@fullyint: aha, thanks! That makes sense and did the trick indeed: [https://staging.ventizo.com/sitemap.xml](https://staging.ventizo.com/sitemap.xml)

Super thanks again for your help.

---

## Post 8 by @fullyint — 2017-09-30T19:49:36Z

Thanks @Henk !

Docs updated in [roots/docs#114](https://github.com/roots/docs/pull/114)

---

## Post 9 by @Henk — 2017-10-02T06:33:45Z

Clear docs now :grinning:
