Skip to content

Instantly share code, notes, and snippets.

@htpcBeginner
Last active May 1, 2019 07:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save htpcBeginner/bae0723c49aac16b57e9 to your computer and use it in GitHub Desktop.
Save htpcBeginner/bae0723c49aac16b57e9 to your computer and use it in GitHub Desktop.
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;
@mehargags
Copy link

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 {
listen xxx.xxx.xxx.xxx:80;
server_name xxxxxx.com www.xxxxxx.com;
error_log /var/log/apache2/domains/xxxxxx.com.error.log error;

location / {
    proxy_pass      http://xxx.xxx.xxx.xxx:8080;
    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/xxxxxx.com/public_html;
        access_log     /var/log/apache2/domains/xxxxxx.com.log combined;
        access_log     /var/log/apache2/domains/xxxxxx.com.bytes bytes;
        expires        max;
        try_files      $uri @fallback;
    }
}

location /error/ {
    alias   /home/admin/web/xxxxxx.com/document_errors/;
}

location @fallback {
    proxy_pass      http://xxx.xxx.xxx.xxx:8080;
}

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/xxxxxx.com/public_html;

include /home/admin/conf/web/nginx.xxxxxx.com.conf*;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment