Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Nginx rewrites for Yoast's WordPress SEO plugin. These rewrites go into the Nginx host file between the server blocks.
# This rewrite redirects sitemap.xml to sitemap_index.xml, which is what Yoast's WordPress SEO plugin generates.
rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
# This rewrite ensures that the styles are available for styling the generated sitemap.
rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
# These rewrites rule are generated by Yoast's plugin for Nginx webserver
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

This comment has been minimized.

Copy link

@mehargags mehargags commented Nov 22, 2016

Where Exactly do you put it inside the Server Block... Pls help
I am using NGinx as Reverse Proxy

server {
error_log /var/log/apache2/domains/ error;

location / {
    location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
        root           /home/admin/web/;
        access_log     /var/log/apache2/domains/ combined;
        access_log     /var/log/apache2/domains/ bytes;
        expires        max;
        try_files      $uri @fallback;

location /error/ {
    alias   /home/admin/web/;

location @fallback {

location ~ /\.ht    {return 404;}
location ~ /\.svn/  {return 404;}
location ~ /\.git/  {return 404;}
location ~ /\.hg/   {return 404;}
location ~ /\.bzr/  {return 404;}

disable_symlinks if_not_owner from=/home/admin/web/;

include /home/admin/conf/web/*;


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.