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

Posted on 2014-08-14
Last Modified: 2014-08-14
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", "");

Open in new window

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

Please help.
Question by:vituxa
    LVL 33

    Accepted Solution

    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.
    LVL 1

    Author Comment

    I found out another way to do this: I've added this in system.webServer tag in Web.Config:

              <rule name="Anything" stopProcessing="true">
                <match url="(.*)$" ignoreCase="true" />
                <action type="Redirect" url="" redirectType="Permanent" />

    Open in new window

    LVL 1

    Author Comment

    but you did help me - Thank you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now