Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just changed my blogging software and I have now the problem that I want to redirect my old imported blog post to the new url pattern.

My old pattern looks like:


Now I want to redirect this url to:


How can I do this using the Web.config for a HTTP 301 Moved Permanently message? I just found solutions to redirect a single url, but not with dynamic placeholder. I need to remove the year, month and day part from the url and then cut off the file extension from the post name.

I came from Blogengine.Net and switched to Funnelweb. I have shared web space on a Windows Server 2008, so I've only FTP access.

Thank for any advice


Add this to the Application_BeginRequest block:

UriBuilder uri = new System.UriBuilder(Context.Request.Url);
Regex r = new Regex(@"^/blog/post/\d+/\d+/\d+/([A-Za-z0-9\-]+)");
Match m = r.Match(uri.Path);
if (m.Success)
   String postName = m.Groups[1].ToString();
   uri.Path = "blog/" + postName;
   Response.Status = "301 Moved Permanently";
   Response.AddHeader("Location", uri.ToString());

Pleas let me know if you have improvements for this.

share|improve this question

migrated from serverfault.com Jan 14 '12 at 14:39

This question came from our site for system and network administrators.

Can you add the blog and web server software you are using? Do you have a shell access? – jflaflamme Jan 14 '12 at 14:58
Sure, I added this information. – NKnusperer Jan 14 '12 at 15:52
up vote 0 down vote accepted

I do not know how to do it in web.config (I do not know if possible or not)

But I do know a way to do this in Global.asax

    protected void Application_BeginRequest(object sender, EventArgs e)
        UriBuilder uri = new System.UriBuilder(Context.Request.Url);
        if (uri.Path == "/blog/post/2011/03/02/my-blog-post.aspx") uri.Path = "/blog/my-blog-post";
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location", uri.ToString());

For the dynamic part, you have to use Regex

if (!Regex.IsMatch(url.Path, @"^/blog/post/\d+/\d+.. sorry, have to go, will come back finish later

share|improve this answer
Thanks, that was a very good idea. – NKnusperer Jan 14 '12 at 18:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.