Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Enterpr1se

    (@enterpr1se)

    I found that the sitemap become of directory rather than a file
    It show http://mydomain.com/sitemap.xml/

    Plugin Author Rolf Allard van Hagen

    (@ravanh)

    It depends on how you have your Nginx rules set up. I’ve got all my sites running on Nginx and with a global rule like

    location / {
    	try_files $uri $uri/ /index.php?$args;
    }

    the request for sitemap.xml will pass to index.php (and thus WordPress) if it does not exist as a static file or directory.

    However, this may fail when there are other rules that target (sitemap).xml requests such as:

    # Cache static files
    location ~* \.(txt|xml|css|rss|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|swf)$ {
    	access_log off;
    	log_not_found off;
    	expires max;
    }

    This will take prevalence over the general rule for all .xml requests. In such a case, just take both xml and txt (needed for the robots.txt request to pass to WordPress) out of the list.

    Thread Starter Enterpr1se

    (@enterpr1se)

    Thanks.

    I found the “Cache static files” does not have xml in it.
    I am using Easyengine, It have some config for Yoast, but I don’t know how to rewrite it

    # Yoast sitemap
    location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
      rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
      rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
       Rules for yoast sitemap with wp|wpsubdir|wpsubdomain
      rewrite ^.*/sitemap_index\.xml$ /index.php?sitemap=1 last;
      rewrite ^.*/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
       Following lines are options. Needed for WordPress seo addons
      rewrite ^/news_sitemap\.xml$ /index.php?sitemap=wpseo_news last;
      rewrite ^/locations\.kml$ /index.php?sitemap=wpseo_local_kml last;
      rewrite ^/geo_sitemap\.xml$ /index.php?sitemap=wpseo_local last;
      rewrite ^/video-sitemap\.xsl$ /index.php?xsl=video last;
      access_log off;
    }

    Plugin Author Rolf Allard van Hagen

    (@ravanh)

    Ah yes, the Yoast sitemap rules that come with EasyEngine will interfere… Just remove them, unless you are using Yoast SEO and any of its paid addons. And then do a nginx -t && service nginx reload of course.

    Can you share a link to your sitemap? I can check if all is working as it should 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Is there any rewrite rule needed to add in nginx server?’ is closed to new replies.