Adnan123
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?

#redirects#webconfig#dotnet
Avatar for member Chedders
Chedders
Moderator (163 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
Response.RedirectPermanent("http://domain.com/newpage");

For a 302 redirect
Response.Redirect(("http://domain.com/newpage");

Or if adding to .aspx page
<% Response.Redirect("http://domain.com/newpage"); %>

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

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

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

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?
2
0
Comments 0
login to reply
Copyright ©2020 SEOChat. All Rights Reserved.