Adnan123 asked
Member (7 upvotes)

How to do SEO safe 301 redirects in a web.config (.NET)?

I see plenty of answers for how to do a 301 redirect for htaccess. The problem is, there is very little help for 301 redirects (which Google will like) for the web.config. Could any ASP.NET guru's help me out, please?

Avatar for member Chedders
Moderator (243 upvotes)

You have a few options in .net

If you wish to work at page level you can add the follow to your c# code

for a 301 redirect

For a 302 redirect

Or if adding to .aspx page
<% Response.Redirect(""); %>

If you wish to do it from the web.config file, 1 option is to use the rewrite module

<rewriteMap name=”Redirects”>
<add key=”/oldpage.aspx” value=”/newpage.aspx” />
<add key=”/oldpage2.aspx” value=”/newpage.aspx” />

if you start having a lot of redirects you can store these in an external file so
<rewriteMap name=”Redirects”>
<add key=”/oldpage.aspx” value=”/newpage.aspx” />
<add key=”/oldpage2.aspx” value=”/newpage.aspx” />

Then add to web.config
<rewriteMaps configSource=”MyRewriteFile.config” />

To be honest I personally do majority of my redirects at page level as there is less room for error.

One word of caution though, you need to make sure you dont redirect a page to a page that is then redirected.
This creates a redirect chain which google wont keep following. By all means do 1 redirect but as you are in charge of your own site you can control the number of redirects, i.e. allwos redirect to the final page.

Good advice?
Comments 0
login to reply
Copyright ©2024 SEOChat. All Rights Reserved. Owned and operated by Search Ventures Ltd and Chris Chedgzoy.