[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

How do I make IIS respond with 301 instead of 404?

Hi Experts.
Is there a way I can make IIS respond with 301 instead of 404?

I have this domain name that used to be a very powerful website. No matter what link is clicked I need to 301 it to somewhere else.

I set up a default.aspx file that has this code in it:

protected void Page_Load(object sender, EventArgs e)
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Status = "301 Moved Permanently";
        Response.AddHeader("Location", "http://www.sitetoredirectto.com");
    }
}

Open in new window


but that only catches it for a main domain name. So if someone goes to www.thisnewdomainigot.com it works, but if someone goes to www.thisnewdomainigot.com/whateverlinkthisis.html it doesn't and still 404s.
I need to make Google think there isn't any 404s. How can I do that ?

Please help.
0
vituxa
Asked:
vituxa
  • 2
1 Solution
 
Paul MacDonaldDirector, Information SystemsCommented:
One way would be to create a custom error handler and parse 404 errors for requests to the old domain.  If you find a 404 for the old domain, you could direct the request to a page that has the 301 redirect built in.
0
 
vituxaAuthor Commented:
I found out another way to do this: I've added this in system.webServer tag in Web.Config:

<rewrite>
        <rules>         
          <rule name="Anything" stopProcessing="true">
            <match url="(.*)$" ignoreCase="true" />
            <action type="Redirect" url="http://www.thesiteimredirectingTO.com" redirectType="Permanent" />
          </rule>
       </rules>
</rewrite>

Open in new window

0
 
vituxaAuthor Commented:
but you did help me - Thank you.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now