In Search of Optimization

A Mike Lopez Search Engine Optimization Blog
Our Home Subscribe to our Feed

If you are a Wordpress user and are conscious about your Search Engine Ranking, then like me, you might have already installed two of the most useful Wordpress plugins that has to do with Search Engine Optimization namely, the Google Sitemaps Plugin and the Subdomain Plugin. If so, good for you.

There is one problem with installing both plugins though. Take a look at this:


http://www.mikelopez.info/
2006-02-28T12:31:01+00:00
daily
1



http://science-and-technology.mikelopez.info/2006/02/27/comet-pojmanski-by-eric-africa/
2006-02-28T12:31:01+00:00
weekly
0.1



http://articles.mikelopez.info/2006/02/27/miscommunication/
2006-02-27T19:39:48+00:00
weekly
0.1

The above sitemap entries were taken from the sitemap.xml file generated by the Google Sitemaps plugin in Wordpress. At first glance, there appears to be no problem with the above sitemap entries until you submit them to Google.

One rule with Google sitemaps is that sitemap entries should be located under the same domain name. Google however treats subdomains as different domain names. This means that Google will complain about certain entries in your sitemap that doesn’t belong to the same domain name.

Some may say that it’s OK. Just submit the same sitemap file for each subdomain and ignore the errors. Though this may work, I decided to be a bit cautious and gave google what it wants - an error free sitemap file.

So, what did I do? I wrote a script. To demonstrate how the script works, simply check the following links (each link will open in a separate window and may take some time to load).

As you can see, the above links provide sitemap files that have been ‘cleaned’ - meaning, not containing entries from different domain names / subdomain names. Furthermore, the above sitemap files are generated on the fly by reading the sitemap.xml generated by the Google Sitemaps plugin and ‘cleaning’ it so that it returns only entries matching the subdomain that was used to access the sitemap.xml.php file.

Now, you can submit each sitemap file for each subdomain and see no more entry but instead of submitting sitemap.xml or sitemap.xml.gz, you will now be submitting sitemap.xml.php. This time, Google will no longer complain :D

Want to do the same on your Wordpress site? If so, just download the file below:

sitemap_cleaner.zip - 713 bytes

Here’s how to use it.

  1. Unzip the file
  2. Edit sitemap.xml.php and change the line that says:
    $map = str_replace (”http://www.mikelopez.info/”, “http://” . $host . “/”, $map);
    - to -
    $map = str_replace (”http://www.yourdomain.com/”, “http://” . $host . “/”, $map);
  3. Upload the file to your Wordpress web folder
  4. Give it a try by accessing www.yourdomain.com/sitemap.xml.php and sub.yourdomain.com/sitemap.xml.php.

One last note, this only works as expected on subdomains that are created by the Wordpress Subdomain Plugin and on the sitemap.xml file generated by the Google Sitemap plugin for Wordpress.

If you have questions, comments, suggestions, just post them below.

Ciao!


16 Responses to “Google Sitemaps and Wordpress Subdomain Plugin”

  1. Gilad.G Says:

    Mike,

    I saw your post here: http://tools.webguerrilla.com/wordpress-subdomain-plugin/

    I posted a response with my .htaccess copy, but here it is again (in case it takes a while to get approved…):
    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    Do you see anything wrong with it?

    Thanks in advance,
    Gilad.

  2. Mike Lopez Says:

    Hi Gilad,

    There seems to be nothing wrong with it. I have a few more questions.

    Based on your post in webguerilla, you mentioned that you’ve set your permalink to ‘/%postname%/’ and that you get the following error:

    ***
    I now have http://uncategorized.myblogs.com/sub-cat/ and http://uncategorized.myblogs.com/sub-cat/hello-world/ both return a Wordpress “Error 404 - Not Found” page.
    ***

    Have you tried just http://uncategorized.myblogs.com/hello-world/ ? Try to remove sub-cat.

    Mike

  3. Gilad.G Says:

    Yes, that returns the correct post, that is http://uncategorized.myblogs.com/hello-world/ shows the post although the post is assigned to the sub-cat category.

    I guess my main goal is to create a multi blog site, but instead of manually creating these subdomains, use this plugin and work off one installation. The issue is that if I have http://uncategorized.myblogs.com/ as a blog, I cannot use categories as it would notmally be if done manually… (hope I explained myself…)

  4. Gilad.G Says:

    Hi Mike,

    Yes, the latter does work, however, the post Hello World is not associated with Uncategorized but with Sub-Cat which is a child of Uncategorized.

    Thanks again for your help.
    Gilad

  5. Mike Lopez Says:

    Hi Gilad!

    You may want to try to put ‘/%category%/%postname%/’ in your permalinks instead. Hope it works!

    Mike

  6. Mike Lopez Says:

    Gilad,

    In addition, you may want to take a look at this:
    http://codex.wordpress.org/Using_Permalinks

    Mike

  7. somerset Says:

    i try to find something at google.com and take it on your site…thanks

  8. mick Says:

    I like what you have to say. I’m going to tell my friends.

  9. Mike Lopez Says:

    Thanks mick!

  10. Tim Linden Says:

    You forgot to mention to edit this line to have your own main URL:
    $map = str_replace (”http://www.mikelopez.info/”, “http://” . $host . “/”, $map);

  11. Mike Lopez Says:

    Hi Tim! Yes, you’re right. Thanks for mentioning it. I edited my post to include that now. :D

  12. Charlee Says:

    Hi Mike,

    I clicked on the links and I’m directed to the homepage. what happened to the sitemap?

    Charles

  13. Nick Says:

    Excellent post.. I am already using the subdomain plugin and will definitely implement this sitemap hack! There are other instances where the subdomains can screw things up. One is most breadcrumb plugins don’t work. I have edited one so that it works with subdomains, and have written a tutorial about it at http://php.codeislogic.com/subster-rejuvenation-breadcrumbs any chance you could mention me in the main article? I will do the same.

  14. gmb Says:

    it works perfect :) in my site (http://www.cochez.es/). thx.

    Maybe we need a plugin to add sitemap automatically to google sitemaps :P

  15. Todd T. Says:

    Mike,

    Thanks for the cool sitemap insight. Questions are as follows:

    Will these plugins work for WP 2.5? I noticed no updates or comments after November 2007.

    It also appears the originator of subdomain plugin you referenced (Greg Boser) is no longer offering or supporting the plug in. Are you using a different subdomain plug in or are you using the one written by Greg Boser?

    I noticed your blog is applying subdomains beautifully. What version of WP and plug in are you using?

    Thanks

  16. Mike Lopez Says:

    Hi Todd,

    Sorry for this “long overdue” reply. I’m no longer using the plugin. As for the subdomains, I switched over to Wordpress MU to handle it as it makes it easier for me to manage my templates and plugins.

    Mike

Leave a Reply


In Search of Optimization · Template by Mike Lopez

Good luck to The Busby SEO Challenge