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?

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

Open in new window

LVL 32
Jamie McAllister MVPSharePoint ConsultantAsked:
Who is Participating?
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 SoudaniSystem Support EngineerCommented:
void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup

    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://website.net"))
    {
        HttpContext.Current.Response.Status = "301 Moved Permanently";
        HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://website.net", "http://www.website.net"));
    }

}

Source:
https://stackoverflow.com/questions/2111955/global-301-redirection-from-domain-to-www-domain
0
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.
0

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?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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:
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-outbound-rules-to-add-web-analytics-tracking-code
0
Jamie McAllister MVPSharePoint ConsultantAuthor Commented:
Turned out my web.config changes were fine, and the error stemmed from something else entirely.
0
Jamie McAllister MVPSharePoint ConsultantAuthor Commented:
Thanks for getting me to check the status using Fiddler, put me onto the right track.
1
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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.