Skip to content

Instantly share code, notes, and snippets.

@jdevalk
Created April 9, 2013 13:57
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jdevalk/5345872 to your computer and use it in GitHub Desktop.
Fix XML sitemaps to work by forcing .htaccess to pick them up. Add this to the .htaccess, above the WordPress rewrites. This version assumes you're using a subfolder install with WordPress installed in /wordpress/, adapt if needed.
# WordPress SEO - XML Sitemap Rewrite Fix
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^sitemap_index.xml$ /wordpress/index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /wordpress/index.php?sitemap=$1&sitemap_n=$2 [L]
# END WordPress SEO - XML Sitemap Rewrite Fix
@lawrencetaur
Copy link

whats the nginx alternative for this.

your plugin generates
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

but that doesnt work, i get 404s. my sub directory is domain.com/blog/

@benarent
Copy link

I also have an install of nginx that forces closing /

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# WordPress SEO - XML Sitemap Rewrite Fix
RewriteRule ^sitemap_index.xml$ /wordpress/index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /wordpress/index.php?sitemap=$1&sitemap_n=$2 [L]
# END WordPress SEO - XML Sitemap Rewrite Fix
</IfModule>

http://nblog.airbrake.io.php53-5.ord1-1.websitetestlink.com/wp-admin/admin.php?page=wpseo_xml
http://airbrake.io/blog/sitemap_index.xml/

@ex-jedi
Copy link

ex-jedi commented Sep 18, 2014

Yep, seems to work fine. Thanks for that!

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