I've been pondering how to make my weblog more friendly to search engines. This is part 1 of that process.
Older search engines did not index any URL with "get" method encoding (e.g. the ?p=85&c=1 URLs b2 uses for permalinks and comments). And I've been told even Google downgrades such links somehow, though I don't know that personally.
Anyway, I came up with a fairly simple way to make permalinks use a different format. This uses apache's rewrite rules from an htaccess file. Many but not all servers allow rewrite rules in .htaccess files, so that would be something to check before starting or when you run into trouble. (Note: all this works from apache config files as well, for those of you who maintain your own servers)
If you have trouble, feel free to
drop me a line. Many of the things I outline here may vary slightly at your server, and I'm glad to help out.
All that said, here's how you do the trick.
1. Decide what path to use for permalinks. In this example and in my website I use the /permaLink directory. the only requirement is that it's not used for anything else on your site.
2. Create or modify the .htaccess file to do the rewrite. This is done in two lines:
RewriteEngine On
RewriteRule permaLink/([0-9]*) /index.php?p=$1&c=1
index.php is the address of my weblog. If yours has a different filename, substitute that in.
3. Upload and test the .htaccess file. On my setup, http://ncyoung.com/permaLink/85 returns the same info as http://ncyoung/index.php?p=85&c=1. Both URLs continue to work.
4. Once you have that working, you can change the permalink format in your weblog. Rather than re-write permalink_single() or the other built in b2 template functions, I commented that out in my page and used instead:
<A HREF="/permaLink/<?=the_ID()?>">permalink</A>
5. Make all the links in your template page absolute so that they don't break under the new path. Don't forget your stylesheet links.
If you have lots of hyperlinks and you want to leave them relative, you can use the following line in your .htaccess file:
RedirectMatch permanent permaLink/(([^0-9]).*) http://yourdomain.com/$1
That should do it! Again,
email me if you have trouble!
update: download the new version of my refererLib.php, updated to work with this hack.