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).
- www.mikelopez.info/sitemap.xml.php
- articles.mikelopez.info/sitemap.xml.php
- science-and-technology.mikelopez.info/sitemap.xml.php
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
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.
- Unzip the file
- 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); - Upload the file to your Wordpress web folder
- 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!
March 5th, 2006 at 9:09 am
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.
March 5th, 2006 at 9:00 pm
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
March 8th, 2006 at 4:44 pm
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…)
March 11th, 2006 at 3:28 am
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
March 11th, 2006 at 11:04 am
Hi Gilad!
You may want to try to put ‘/%category%/%postname%/’ in your permalinks instead. Hope it works!
Mike
March 11th, 2006 at 11:06 am
Gilad,
In addition, you may want to take a look at this:
http://codex.wordpress.org/Using_Permalinks
Mike
June 22nd, 2006 at 9:49 pm
i try to find something at google.com and take it on your site…thanks
December 5th, 2006 at 2:57 pm
I like what you have to say. I’m going to tell my friends.
December 13th, 2006 at 6:13 pm
Thanks mick!
February 14th, 2007 at 11:10 am
You forgot to mention to edit this line to have your own main URL:
$map = str_replace (”http://www.mikelopez.info/”, “http://” . $host . “/”, $map);
February 14th, 2007 at 11:14 am
Hi Tim! Yes, you’re right. Thanks for mentioning it. I edited my post to include that now.
June 5th, 2007 at 9:32 pm
Hi Mike,
I clicked on the links and I’m directed to the homepage. what happened to the sitemap?
Charles
August 25th, 2007 at 3:19 am
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.
November 10th, 2007 at 3:11 am
it works perfect
in my site (http://www.cochez.es/). thx.
Maybe we need a plugin to add sitemap automatically to google sitemaps
June 3rd, 2008 at 2:50 am
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
June 10th, 2008 at 6:24 pm
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