Programming SEO – Cross Linking Titles

Here is another interesting way to programmatically add link juice to web pages from within your own site. It will require that you have pages created dynamically from a database and that you have some way of retrieving the title.
You’ll remember that one of the ways of helping a page rank in the search engines is by providing links to that page that say what that page is about. What better indication of what a page is about than the title?
So what you’ll need to do on each page is to gather a list of all the pages and their titles on your site, search for content on your page that matches each of those titles, and then hyperlink each phrase to the corresponding page on your site.
To do this, I’d recommend using regular expressions.
Given a title of “The Quick Brown Fox” you’d want to find any occurrence of that string that had any number of white space characters between the words and in any mix of casing.
The regular expression for that is:
the\s+quick\s+brown\s+fox
So, for any title, you’d want to initialize your RegEx like this
Regex rx = new Regex(title.ToLower() .Replace(" ", @"\s+"),RegexOptions.IgnoreCase);
This assumes that there is only one space between each of the words in your title.
To replace the text in your article with a hyperlink using this text you’d use
body = rx.Replace(body,
"<a href='locationOfTheArticleHere'>$0</a>");
This technique works best on page titles that are relatively short. If your titles tend to be longer, as mine do, you might want to provide a list of possible linking phrases for each article. In that case, I’d link to the titles first and then make a second pass for the linking terms if and only if a title was not found in the article.
The other obvious problem with this technique is that it could take a long time to generate the page if you have a lot of articles and you do this every time the page is displayed. If this is the case, you’ll want to implement some caching mechanism either by using what is built into .NET or by using some other implementation that caches on a more permanent basis.
Other post in Seach Engine Optimization
- SEO From a Programming Perspective - Theory - May 19th, 2009
- Programming SEO – Tags and Keywords - May 28th, 2009
- Programming SEO – Cross Linking - June 3rd, 2009
- Google NOFOLLOW Change (and why this isn’t news) - July 16th, 2009
- Programming SEO – Cross Linking Titles - August 13th, 2009
- ASP.NET Google SPDY Tweaks - November 17th, 2009
- Forming CT SEM Think Tank - February 2nd, 2010
Nice! Interesting way to ensure consistency of links across a site.