January 12th, 2008 at 6:23 pm

Looks like document root, but is in a subfolder

Are you using Google Sitemaps, and does your website have very many pages? Then you will usually have a sitemap index file along with a number of sitemap files in your document root. Now, you might want to tidy up and move those sitemap files to a subfolder -- but that doesn't work, as Google requires the sitemap files to be in the document root. What to do? You can use mod_rewrite to solve this:

Create the directory gg_sitemaps and move your sitemaps index as well as all your sitemap files there.

Add the following line to the file .htaccess in your document root (if it doesn't exists, create it):

CODE:
  1. RewriteRule ^(sitemap.*)$ /gg_sitemaps/$1 [L]

(Note: This assumes that your sitemap index and the sitemaps files start with the string sitemap, e.g. your sitemap index file it could be sitemaps.xml, while the sitemaps files could be sitemap0.xml, sitemap1.xml and so on.)

Now your sitemaps are out of the document root, but Google will still see them as if they were in there.

By the way, this also works for the Google sitemaps verification files: If you want to verify your site in Google Webmasters, you need to upload a file to your document root. (You could also add a meta tag, but that's not so good.) Adding a single file isn't a problem, but if you want to allow different people to manage this domain in different Google Webmaster accounts, or if you have multiple domains in the same document root, you will need to upload more than one file. Again, we can solve this with some mod_rewrite magic:

Create the directory gg_verify and move all your verification files there.

Add another line to the file .htaccess in your document root:

CODE:
  1. RewriteRule (^google.*$) /gg_verify/$1 [L]

Again, Google will think, the respective file is in the document root, while actually it is in the designated subfolder.

Leave a Comment