I've been rather quiet on the blogging front lately, but not for lack of activity! For one, I'm the full owner of the technical posts that go up on Microsoft's dev blogs for Windows, http://blogs.windows.com/windows/b/buildingapps/, which merged together the Windows and Windows Phone dev blogs back in early April. Call me the developmental editor for just about anything posted under the "Windows Apps Team" byline.

But no excuse for personal blogging! These last few weeks I haven't wanted to add anything to my blog here because I've been migrating my site from godaddy.com (where the hosting cost went up and it's hard to find discounts now) to Microsoft Azure, where my Windows Store account gives me $150/month credit! (I believe you all are enjoying that too.) The trick was to migrate and merge my old ASP.NET site content with my WordPress blog content, which also meant redirecting the blog from a /blog subfolder to the root while getting the .aspx pages to redirect properly, especially Pages.aspx, which did a database lookup for articles and such that are now WordPress pages.

If you see some bad links or broken images in any posts here, let me know (kraig(at)kraigbrockschmidt.com). I'm doing a scrub but might miss something.

One issue that I ran into was rather interesting. With WordPress I wanted to switch from default permalinks using /?p=<post ID> URIs to "pretty name" URIs with dates and such (better for SEO). At the same time I wanted to make sure that /blog/<name> got redirected to just <name> give that I pulled WordPress into the site root.

Should have been easy with an Azure virtual directory, yes? At first, that seemed to work just fine–I added an entry on the Azure web site Configure page for /blog to go to sitewwwroot. I tested it, and it was good.

But when I changed the WordPress permalinks, I started getting either HTTP 404 errors or HTTP 500 errors when using /blog. What gives?

It boiled down to the fact that WordPress was interpreting /blog as part of a pretty name and therefore trying to do a post or page lookup, and not finding one would generate a 404. The 500 errors showed up when I had some Rewrite rules in web.config (that WordPress included for pretty permalinks), which seemed to generate confusion between the permalink system and Azure's virtual directory checking.

In the end, the solution was to insert a special redirect rule in web.config for "blog" specifically, so it'd get processed first and bypass the permalink system entirely. Here's what my web.config looks like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".svg"/>
      <mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
    </staticContent>

    <rewrite>
      <rules>
        <rule stopProcessing="true" name="Blog Rule">
          <match url="blog"/>
          <action url="index.php" redirectType="Permanent" type="Redirect"/>
        </rule>
        <rule name="wordpress" patternSyntax="Wildcard">
          <match url="*"/>
          <conditions>
            <add negate="true" matchType="IsFile" input="{REQUEST_FILENAME}"/>
            <add negate="true" matchType="IsDirectory" input="{REQUEST_FILENAME}"/>
          </conditions>
          <action url="index.php" type="Rewrite"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

 

Hopefully this helps others who run into the same thing every now and then!