Roots Discourse

Rewrite XML sitemaps w/ Nginx includes

I’m using the Google XML Sitemaps 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:

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 What am I missing here? Thanks in advance!

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.

Does <site_name> in your path match the site key exactly? It wouldn’t work if it matches one of the site_hosts, 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 For example, if you are using a version older than Dec 1, 2016, the nginx-includes path will not work (e.g., see docs diff for where includes were before).

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
      - canonical:

Exact location of my rewrites.conf.j2: /nginx-includes/ 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.

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?

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

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 to clarify this placement.
├── site
└── trellis
    └── nginx-includes
1 Like

@fullyint: aha, thanks! That makes sense and did the trick indeed:

Super thanks again for your help.

1 Like

Thanks @Henk !

Docs updated in roots/docs#114


Clear docs now :grinning: