Nov 10

Written by: Bruce Chapman
Monday, November 10, 2008 11:51 AM 

I've been waiting eagerly for the new Blog module to be released.  Quite a while back, I posted on here how the Blog module developers could make people happy by putting the module title into the Url using the 'page name' functionality of the Friendly Url API.   One of my readers thought it was a good idea and posted it on Gemini, now the results are in.  Here's my experience with the upgrade.

It was back in my post 'An open letter to the DotNetNuke developers of the world : please start using the FriendlyUrlProvider API for custom page names' that I originally made a suggestion that the Blog developers change the DNN Blog module code to include the Blog entry title into the Entry Url.  This latest release (version 3.5) includes this functionality : a job well done.  Note that I'm not taking credit : all I did was talk about it, others took the actions of requesting through Gemini and actually coding and testing the solution.

But there's more.  Not only did they implement a good scrubbing routine to clean up Blog titles and output nice Url-standard ASCII, they also put in a 301 redirect to move all your old Blog posts in search engine indexes and favourites locations over to the new one.  They've also added Gravatar icons and modified the page title so that the Blog title appears in it.  These are all great additions to the blog platform and much needed SEO improvements.

However, it wasn't all plain sailing for me.  iFinity Forums user CodeGecko posted yesterday that his code was in a 301 redirect loop when trying to access blog posts using the iFinity Friendly Url Provider.  That sounded quite grave, so I immediately installed Blog 3.5 on my test environment and checked out the blog posts.  Everything was as you'd expect : no problems at all. 

I was impressed with how easy the upgrade had gone, so I gallantly decided to upgrade the ifinity.com.au site blog module.  Oh dear - instant 301 redirects on all blog entries, just as CodeGecko had reported.  Cue panic and 'I wish I had taken a backup' moment.  There's a difference though - this site uses the Url Master module, not the Friendly Url Provider.  Still, there was obviously a problem.

Nevertheless, in life you can either complain about problems or do something about it.  I cracked open the Blog module code, and found where the 301 redirect is issued, around line 183 of  'ViewEntry.ascx.vb':

 

Dim showSeoFriendly As Boolean = Convert.ToBoolean(m_oBlogSettings("ShowSeoFriendlyUrl"))
Dim correctUrl As String = Utility.BlogNavigateURL(TabId, m_oEntry, showSeoFriendly)
 If (Not requestedUrl Is Nothing AndAlso Not requestedUrl.EndsWith(correctUrl)) Then 'See Note
    'NOTE: We use EndsWith here because 
    'NavigateURL returns a relative URL to BlogNavigateURL
    '    when friendly URLs is not turned on for the portal.
    '301 Redirect to the correct format for the page
     Response.Status = "301 Moved Permanently"
     Response.AddHeader("Location", correctUrl)
     Response.End()
  End If

 

 Now, I'm not the one to ever point bugs out with glee, because as a developer, I'm in the daily business of finding bugs of my own making, but there's two bugs in this bit of code

 

 

Bug 1 : Ignores the SEO Url Switch on doing 301 redirects

The redirect switch is saved in the 'Blog Options' page : you can turn the 'SEO Urls' off if you like. This is useful, but the unfortunate thing is, you need to be able to turn off the redirects somehow, if they're causing grief (as mine were). Unfortunately, you can't. There's no off switch, even if you turn off the SEO Urls.

SolutionEither put 'If (ShowSeoFriendly and (not requestedUrl is nothing....) - in effect only redirecting if the Seo Friendly Urls are switched on, or create a new option in the Blog Options page to allow the 301 redirects to be switched off. 301 Redirects are a very blunt stick : you go here no matter what : You always need an off switch. I found out this very early on in my 301-redirecting career

Bug 2 : Case insensitive compare

Another problem with doing this type of redirect is that the Url isn't case sensitive. This was actually the issue in my case. My portal Alias entry was 'www.iFinity.com.au' - which, after being processed by IIS/ASP.NET/DNN, was coming through as www.ifinity.com.au : hence, the .EndsWith() comparison fails comparing iFinity.com.au/My-Long-Blog-Title and ifinity.com.au/My-Long-Blog-Title. You could also point the finger at the Url Master module for not generating a lower-case version of www.ifinity.com.au - in fact both modules are probably at fault here. But the Blog module could would be better served with a case-insensitive comparison.

I've posted this here not to try and show up the Blog module developers : far from it, I think the changes are excellent and I'm excited to try out the WLW functionality. But if someone comes along to my site and says 'hey my blog module is in a 301 redirect loop because of your product' I can at least point them to how to patch their blog module code or troubleshoot their install. And hopefully some others will come along looking for how to implement 301 redirects into their code for SEO goodness.

My Changes to get my Blog Module Running Again

To clarify : these changes didn't fix the problem : it merely allowed me to discover what was wrong.  What was actually wrong was that my portal Alias was a mixture of upper and lower case : all I had to do was update the portalAlias table manually to get the problem fixed.

Here's my changes as I made to the module (running this very page)

Dim showSeoFriendly As Boolean = Convert.ToBoolean(m_oBlogSettings("ShowSeoFriendlyUrl"))
Dim correctUrl As String = Utility.BlogNavigateURL(TabId, m_oEntry, showSeoFriendly)
 If (showSeoFriendly And (Not requestedUrl Is Nothing AndAlso Not requestedUrl.EndsWith(correctUrl

,StringComparison.InvariantCultureIgnoreCase

))) Then 'See Note 'NOTE: We use EndsWith here because 'NavigateURL returns a relative URL to BlogNavigateURL ' when friendly URLs is not turned on for the portal. '301 Redirect to the correct format for the page Response.Status = "301 Moved Permanently" Response.AddHeader("Location", correctUrl) Response.AddHeader("X-Blog-Redirect-Reason", _ "No match for requested Url (" & requestedUrl & " _ and correct url " & correctUrl) Response.End() End If

You'll note that I also added in an informational response header : I just like to do this sort of thing, so when you get a 301 redirect you at least know why/which bit of code did it.

Oh, and another thing : I notice that after I installed my module, all my posts came up again on Google reader. It seems that changing the permanent links also updates your blog posts in RSS readers.

Copyright ©2008 Bruce Chapman

Tags:

7 comment(s) so far...

Re: Installing the New DotNetNuke Blog Module version 3.5

Just as a PS : I've created a Gemini request on my suggestions, which covers what I've posted above :

support.dotnetnuke.com/issue/ViewIssue.aspx?ID=8724&PROJID=23

By Bruce Chapman on   Monday, November 10, 2008 12:53 PM

Re: Installing the New DotNetNuke Blog Module version 3.5

Excellent post Bruce, and I take full responsibility for the oversights in the code and apologize for the grief the 301 redirects caused. I didn't experience any issues at itcrossing.com, but that's probably because I've used the option in URL master to force lower case and all my portal alias URLs are lower case.



Thanks for creating the Gemini ticket and I’m sorry for not reaching out to you for help with this as I should have. At the time, I don’t think I realized what an SEO expert you are. Anyway, your suggestions will definitely make this aspect of the blog module right in the next build.



Thanks again!

By Don Worthley on   Wednesday, November 12, 2008 12:22 PM

Re: Installing the New DotNetNuke Blog Module version 3.5

Bruce - I was going to post a comment on your blog, but can't because the CAPTCHA isn't displaying for me. I need to find out if there is a bug in the blog module that is causing it to not display for some reason (our problem), or if you've made a change to your code that has broken the CAPTCHA (your problem). Thanks for the information on the 301 issue!! Rip Rowan (blog team)

By Rip Rowan on   Wednesday, November 12, 2008 12:22 PM

Captcha Issues

Hi guys, thanks for the comments.

I don't know why the captcha broken when I upgraded. I even tried upgrading my DNN to 4.9 to see if that would fix the problem. I run a standard build, no changes. Of course this site is running the Url Master software, but I've checked and it's not interfering with the captcha url. In addition, my test site which is more or less a clone of this site (same dnn version, same blog version, same url master version) the captcha is working fine.

I've checked the event logs, and it's the dreaded ' Input string was not in a correct format. at System.Number.StringToNumber' inside the captcha code which is causing the captcha to break. I've seen other people reporting this error but no resolution as far as I can tell.

Interestingly enough, I traced it down to the call :
'Dim width As Integer = Integer.Parse(Settings(0))'
...and Settings(0) comes from splitting this line:
Dim Settings As String() = Split(encodedText, _Separator)
..where _Separator = ":-:".

Personally, I think there should be a bit more robust error handling around this call - but at any rate, that's where the problem is. The decrypted request, when split up with the separator, doesn't yield a valid integer. I don't know if this is a problem with the decryption, the encryption, or what.

By Bruce Chapman on   Wednesday, November 12, 2008 12:29 PM

Re: Installing the New DotNetNuke Blog Module version 3.5

I just thought I'd add a little addendum.

After 4 days, the Google search index is already showing updated page titles and Urls for my highest-PR blog posts. Just more proof of how effective 301 redirects are in making sure that your content is indexed in the best possible way. I'll now have to monitor how much my posts traffic increases as a result of increased rankings and more descriptive titles.

By Bruce Chapman on   Friday, November 14, 2008 3:47 PM

Re: Installing the New DotNetNuke Blog Module version 3.5

Hi Bruce,

Just to let you know, I was unable to build the Blog module with your amendments. However, I had a bit of a brainwave with regard to the case-insensitive search. As I'm running the Frendly URL provider I've just changed the settings in the web.config to forceLowerCase="true" and redirectWrongCase="true", and lo and behold, my blog is fully functional once again!!

codegecko

By codegecko on   Monday, December 08, 2008 8:04 PM

Re: Installing the New DotNetNuke Blog Module version 3.5

@codegecko

Well, I normally just write pseudo code off the top of my head : very few of my inline code examples actually compile. It's funny, I didn't even think of using the 'lower case' options on my own software. Anyway, my suggestion is really to add in an option in the blog options page to turn the 301 redirect on or off. But Don informs me we could be in for a long wait on the next blog module : lots of changes on the way.

By Bruce Chapman on   Monday, December 08, 2008 10:44 PM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
Need Help?
 

If you're having trouble with an iFinity Product, use the Support Forums to search for answers, and to post questions.

If you need help faster than that, or can't figure out the answer, try our Premium Support service.