Hi there,
I'm trying to setup the Yoast WordPress SEO plugin's sitemap functionality to place nice with nginx and php-fpm.
The plugin uses WordPress built in rewrite rule API (NOT .htaccess or nginx rule based - see here http://codex.wordpress.org/Rewrite_API/add_rewrite_rule).
Therefore it takes a request like http://mysite.com/sitemap_index.xml and rewrites this within WordPress to something like: http://mysite.com/index.php?sitemap=1
There are some other similar rewrite rules that also use the WordPress rewrite API. Here is some example code:
function init() {
$GLOBALS['wp']->add_query_var( 'sitemap' );
$GLOBALS['wp']->add_query_var( 'sitemap_n' );
add_rewrite_rule( 'sitemap_index\.xml$', 'index.php?sitemap=1', 'top' );
add_rewrite_rule( '([^/]+?)-sitemap([0-9]+)?\.xml$', 'index.php?sitemap=$matches[1]&sitemap_n=$matches[2]', 'top' );
}
Here is a copy of my relevant nginx conf for mysite:
# Pass PHP scripts on to PHP-FPM
location ~* \.php$ {
try_files $uri /index.php;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
Can I create a similar rule to pass the .xml requests over to php?
At the moment it looks like nginx is trying to server a sitemap_index.xml file which actually doesn't exist.
Thanks,
Ed