Link to home
Start Free TrialLog in
Avatar of Jamie McAllister
Jamie McAllisterFlag for Switzerland

asked on

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

Avatar of Omar Soudani
Omar Soudani

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
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jamie McAllister

ASKER

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?
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
Turned out my web.config changes were fine, and the error stemmed from something else entirely.
Thanks for getting me to check the status using Fiddler, put me onto the right track.