Redirect with a 301 Status

I've implemented a redirect to a new domain on a legacy BlogEngine install (running on ASP.NET).

The redirect itself works fine. You'll see I'm effectively removing the 'post' folder from the destination url etc.

Issue is that this is returning a HTTP Status of 200. I need to return a 301 for best SEO. I'd thought specifying redirectType of Permanent would have handled that. Any ideas?

        <rule name="redirect" enabled="true">
          <match url="^post/(.*)" />
              <add input="{HTTP_HOST}" negate="true" pattern="^$" />
          <action type="Redirect" url="{R:1}" appendQueryString="true" redirectType="Permanent" />
		<rule name="redirectFolder" enabled="true">
          <match url="(.*)" />
			  <add input="{HTTP_HOST}" negate="true" pattern="^$" />
          <action type="Redirect" url="{R:1}" appendQueryString="true" redirectType="Permanent" />

Open in new window

LVL 32
Jamie McAllister MVPSharePoint ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Omar SoudaniSenior System EngineerCommented:
void Application_Start(object sender, EventArgs e)
    // Code that runs on application startup

    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(""))
        HttpContext.Current.Response.Status = "301 Moved Permanently";
        HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("", ""));


Kyle AbrahamsSenior .Net DeveloperCommented:
Are you sure you're not getting a 301?  The 200 should be from the page you're redirecting from.  

Run a program like fiddler to see the 301 before you get to the new page.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jamie McAllister MVPSharePoint ConsultantAuthor Commented:
You're right, with Fiddler I'm seeing a 301, with Postman I wasn't.

However Google Webmaster Tools insists that "We couldn't find any 301-redirect directives for your site".

Am I missing something? I used a .htaccess file to redirect the root (non-ASP.NET) part of my website. But it won't work for the ASP.NET bit.

Is there some other file in my solution I should be tweaking?
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Kyle AbrahamsSenior .Net DeveloperCommented:
are you looking at your home page?  Apparently you need to point at the place you're redirecting to.  

Also please see the following if you're looking for analytics using rewrites:
Jamie McAllister MVPSharePoint ConsultantAuthor Commented:
Turned out my web.config changes were fine, and the error stemmed from something else entirely.
Jamie McAllister MVPSharePoint ConsultantAuthor Commented:
Thanks for getting me to check the status using Fiddler, put me onto the right track.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.