In my latest project I decided to incorporate BlogEngine.Net for managing the content. While it certainly does have some things I don't like, all in all it's an excellent basic content system. I love the control over the HTML that you get with the theme system, the flexibility provided by extensions and widgets, and the integration with Windows Live Writer - truly a job well done by Mads and the BE.NET team!
During A Redesign, Think About Search Visitors
So I have an existing site that is already ranking well in the search engines. When I move the content to BlogEngine, the paths to most of those inner pages is going to change. If I don't redirect the URLs, visitors will be clicking on my search listings only to get 'Oops! Page Not Found' errors. Because there are too many pages to redirect one-by-one, I quickly realize I'm going to need a consistent pattern for rewriting these URLs.
Currently the inner page article URLs are in the form:
I plan to use BlogEngine's 'page' system for these articles, so I plan for the new URLs to be of the form:
During A Redesign, Think About Search Engines
There's one more thing I need to consider here. These articles have been around a while and other sites have linked to them. I'm going to want to keep the 'link juice' that those articles have gained over the years.
To do that, we need to use what's known as a 301 redirect. '301' is the HTTP code for 'Moved Permanently'. It tells the search engines that this new URL actually IS the new location of that old page. By doing this, the search engines will (eventually) consider the two URLs one in the same, and count any links to the old URL the same as links to the new URL.
In my experience, the time it takes for this transition to take place varies and there may even be a period of time when both pages are actually ranking despite the fact that they both end up at the same new URL!
Enter The BlogEngine Regex Rewriter
The Regex Rewriter is a BlogEngine extension that allows you to
control the rewriting or redirecting of URLs. It is based on regular
expressions, but in it's simplest form, you don't need any knowledge of regular
expressions at all to use it.
Step 1) Copy the two code files into your App_Code/Extensions folder. In my case I chose to put them in a subfolder:
Step 2) Register the HTTPModule by adding the following line to the <httpModules> section of your web.config:
<add name="RegexRewriter" type="Dexign.Web.HttpModules.RegexRewriterModule"/>
You should make sure the RegexRewriter module is listed *before* BlogEngine's own UrlRewrite module.
Step 3) Configure your rewrites by logging in to your control panel and clicking on the Extensions tab and then Edit for Regex Rewriter:
There is one section for managing the rewrites and a separate section for managing the redirects.
Basic Usage - Rewrites vs. Redirects
A 'rewrite' is when the server internally serves a different URL than the user specified.
For example, let's pretend you setup the following rewrite with the Regex Rewriter extension:
Now if you navigate to /rewriteme.aspx you will see the content from the BlogEngine default page while the URL remains unchanged (/rewriteme.aspx).
On the other hand, if you setup the following redirect:
When you navigate to /redirectme.aspx the page (URL and all) will actually change to '/default.aspx'. Internally, rewrites are processed first and will take priority over redirects.
Getting Tricky - Using Regular Expressions
If you don't want to manually rewrite/redirect every single URL, you can setup regular expression patterns. For example, to 301 redirect all of my old existing URLs to the new URLs for my new project, I'm using the following redirect setting:
OK, But What Is This Good For?
Here are some things you could use this extension for:
- Moving an existing site to BlogEngine - Redirect those old URLs so your pages keep all of their search engine authority.
- Creating short URLs - You can rewrite to any URL - internal or external. So for example, you could setup '/a.aspx' to redirect to some very long URL that is difficult to remember (similar to what snipurl does).
- Hiding affiliate codes - Rewrite to external sites to hide the use of affiliate codes - for example, rewrite an internal link to an external site with your affiliate code. This is a popular technique among affiliate marketers.
I'm sure there are other uses for this that I haven't thought of. If you do use it, I'd love it if you left a comment below!
Download The Extension
RegexRewriter.zip (2.46 kb)