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

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

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
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
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
Microsoft IIS Web Server

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.