NetInverse Developers Blog

March 31, 2009
Category: Wordpress — Tags: , , — admin @ 9:07 pm

The first principle to optimize permalinks is to ensure that they include your keywords. An URL with a keyword is better than an URL without one for search engines. Following sample uses the category and the post title as part of a Permalink.

For detailed steps, you can check out this blog: http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/. You can also check out MSDN URL Rewriting in ASP.NET.

Following outlines the steps needed to enable WordPress Premera Link on IIS 7.0.  It may just take you 10 minutes.  

  1. Install URL rewrite module Go Live release.
  2. Create a debugging page. This is really optional; it would be handy when you later need to troubleshoot the regular expression rules.  Copy the file to into your WordPress folder.
    <%@ Page Language="C#" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>URL Rewrite Module Test</title>
    </head>
    <body>
          <h1>URL Rewrite Module Test Page</h1>
          <table>
                <tr>
                      <th>Server Variable</th>
                      <th>Value</th>
                </tr>
                <tr>
                      <td>Original URL: </td>
                      <td><%= Request.ServerVariables["HTTP_X_ORIGINAL_URL"] %></td>
                </tr>
                <tr>
                      <td>Final URL: </td>
                      <td><%= Request.ServerVariables["SCRIPT_NAME"] + "?" + Request.ServerVariables["QUERY_STRING"] %></td>
                </tr>
          </table>
    </body>
    </html>
  3. Log into the Wordpress Admin page, choose Settings  -> Permalinks from the left navigation bar. Note following steps are based on Wordpress v2.7.
  4. Change your Permlinks structure to be
    Custom Structure: /%category%/%postname%/%post_id%/
  5.  Run inetmgr.  Click “Start” -> “Run”, type in “inetmgr”, then click the button “Ok”.
  6. Choose your web site,  click the “Url Rewrite” icon from “Features View”.
  7. Click “Add rules”.
  8. Give the new rule a name like “Wordpress page rule”, and define the Pattern and Rewrite Url.
      Pattern: ^MyBlog/([_0-9a-z-]+)/([_0-9a-z-]+)/([0-9]+)/
    
      Rewrite Url: /MyBlog/?p={R:3}
  9. Save the rule, then try out your Wordpress page to see if it works. You may need to creat more rules. Open the web.config, you will see the rules like below.

        <system.webServer>
            <rewrite>
                <rules>
                    <clear />
                    <rule name="wordpress calendar month" enabled="true">
                        <match url="^MyBlog/date/(\d\d\d\d)/(\d\d)" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="/MyBlog/?m={R:1}{R:2}" appendQueryString="false" />
                    </rule>
                    <rule name="wordpress calendar day" stopProcessing="false">
                        <match url="^MyBlog/date/(\d\d\d\d)/(\d\d)/(\d\d)" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="/MyBlog/?m={R:1}{R:2}{R:3}" appendQueryString="false" />
                    </rule>
                    <rule name="wordpress page">
                        <match url="^MyBlog/([_0-9a-z-]+)/([_0-9a-z-]+)/([0-9]+)/" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="/MyBlog/?p={R:3}" appendQueryString="false" />
                    </rule>
                    <rule name="wordpress category">
                        <match url="^MyBlog/category/([_0-9a-z-]+)" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="/MyBlog/?cat={R:1}" appendQueryString="false" />
                    </rule>
                    <rule name="wordpress paging">
                        <match url="^MyBlog/page/([0-9]+)" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="/MyBlog/?paged={R:1}" appendQueryString="false" />
                    </rule>
                    <rule name="wordpress tag">
                        <match url="^MyBlog/tag/([_0-9a-z-]+)" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Rewrite" url="/MyBlog/?tag={R:1}" appendQueryString="false" />
                    </rule>
                    <rule name="wordpress feed" stopProcessing="true">
                        <match url="^MyBlog/feed$" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Redirect" url="/MyBlog/?feed=rss2" appendQueryString="false" />
                    </rule>
                    <rule name="wordpress comment feed" stopProcessing="true">
                        <match url="^MyBlog/comments/feed$" />
                        <conditions logicalGrouping="MatchAll" />
                        <action type="Redirect" url="/MyBlog/?feed=comments-rss2" appendQueryString="false" redirectType="Permanent" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    1. You see, it is easy!

©2009 NetInverse. All rights reserved. Powered by WordPress