Have you changed your domain and don't want to loose your SEO
Do you have renamed a page and don't want to return errors to users that have
saved a bookmark?
You have to perform a 301 permanent redirect to the new
There are plenty of methods to perform this, if you
Google the question you'll
be submerged by the answers.
Curiously the easiest method doesn't come out first.
Let's explore some of the most common methods and then at the end I'll show you
the best one.
Redirecting an ASPX page by code
Place the following code in the ASPX page to be redirected:
protected void Page_Load(object sender, EventArgs e)
The drawback of this method is that you can redirect only ASPX files, if you
have to redirect from an HTML file you cant.
Redirecting an HTML page by client code
window.location = 'http://www.mynewdomain.com/MyNewFile.aspx';
The drawback is that this is only an hack, you'll redirect the page, but not
using a real 301 permanent redirect: your page rank
won't be passed from the old page to the new.
You can add the following meta tag, but you'll never get the same result as a
real 301 permanent redirect:
<link rel="canonical" href="http://www.mynewdomain.com/MyNewFile.aspx"
Redirecting an HTML page by server code
You have to create a class that derives from
intercept all HTML requests.
This is a long and annoying task, especially if not all HTML pages have to be
Did you like this article up to here?
Before you continue, follow us on our Google+ page pressing the button here below!
In this way, we'll be able to keep you updated on digital strategies not only with our posts, but also with the best articles that we collect around the web.
If you want to also press the +1 button, you'll help us spread the article on the web.
The best solution: redirecting by configuration
It is not easy to find this solution on Internet, because you'll find tons of
samples of the previous ones.
If you have IIS 7 or higher that's the best way to redirect!
Simply use the
httpRedirect element of the
section and you'll be able to redirect everything you want, ASPX, HTML, PHP,
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Permanent">
<add wildcard="/MyOldAspFile.aspx" destination="/MyNewFile.aspx"
<add wildcard="/MyOldHtmlFile.html" destination="/MyNewFile.aspx"
This method is very powerful, for example if you have changed the domain but
the pages are the same, you have just to add:
<httpRedirect enabled="true" childOnly="true" destination="http://www.mynewdomain.com/"