301 Redirects for SEO from Windows Server & IIS

This article gives you a quick overview for making SEO friendly IIS 301 redirects from Windows server using the web.config file.

There are other ways to redirect from Windows Server and Dot Net (.Net) but here we are just looking at the path of least resistance for making simple 301 redirects for SEO purposes.

A quick word of note being the bulk of my rewriting experience is with Mod Rewrite under Apache and .htaccess so this had to be easy for myself and subsequently, this is a guide for Windows or non-Windows folk alike. If anyone has any additional resources or suggestions for this article please drop a comment below and I will update the main article.


Windows 301 Redirection Basics


When redirecting for SEO purposes we are hoping to pour the value of a page/site into another page/site. With this in mind, we should always try to point an old page at the most relevant replacement rather than just doing some kind of a catch all hack redirecting all pages to the homepage. Equally, with an eye of avoiding SEO penalties, it makes sense to do things in as non-a-spammy way as possible and sitewide 301 redirects to the homepage are simply not a good idea.

What this means it that your redirection file will most likely have a bunch of specific redirects for individual pages, some whole directories and then some wild card or catch all redirects to mop up any spillage.


1. Web.Config

Your redirections will be made from a web.config file in the site root. So, the first job is to create a web.config (if it does not already exist). You can use FTP or possibly your hosting control panel to get access to your web root.

There are a few things to note about the syntax used for making 301 redirects from IIS on window servers in a web.config file. Firstly,  everything is wrapped up in <configuration></configuration> tags and secondly, the value set in the httpResponseStatus should be ‘Permanent’ to issue the 301 code we are looking for.


2. Basic Redirection

This is your bog standard 301 redirect in the web.config file that you will use for redirecting the bulk of your pages. This takes page A and simply redirects to page B. This is handled instantly for a human visitor or search engine and will pass most of any value from the original page through to the new site.


<location path="page-to-redirect.html">
<httpRedirect enabled="true" destination="http://www.destination.co.uk/new-page.html" httpResponseStatus="Permanent" />


3. Changing URL

This simple redirect points people at a new URL so if you have changed domain BUT the page names are all exactly the same, this one simple rule is all that is required.


<httpRedirect enabled="true" destination="http://www.newdomain.com/" />


4. Catch All 301 Redirection

You may have cause to redirect all pages or all pages that don’t have a specific rule to another page and this will do the job. This is essentially the same rule as above with the exactDestination=”true” rule added to the httpRedirect.


<httpRedirect enabled="true"  exactDestination="true"  destination="http://www.newdomain.com/" />


5. Wildcard 301 Redirect

IIS web.config redirects also support wildcards to redirect a given type of files to another location and this works much like a basic DOS wildcard character with *.* being the catch-all redirect. You will likely want to redirect one type of file, say HTML files for instance so your wildcard would be something more like *.html as below.


Example Web.Config


If one of your redirect rules is triggered, the subsequent rules are ignored. So, a typical approach would be to add some specific rules (2) then finally a catch-all to catch any stragglers.

The set up below gives you a complete example and a template that works this way with specific redirections and a catch all redirection. In the below example we do two specific redirections from old-page-1.html & old-page-2.html and then finish up with a catch-all 301 redirect to send anything left over to http://www.newsite.co.uk/.


<location path="old-page-1.html">
<httpRedirect enabled="true" destination="http://www.newsite.co.uk/new-page-a/" httpResponseStatus="Permanent" />
<location path="old-page-2.html">
<httpRedirect enabled="true" destination="http://www.newsite.co.uk/new-page-b/" httpResponseStatus="Permanent" />
<httpRedirect enabled="true" exactDestination="true" destination="http://www.newsite.co.uk/" httpResponseStatus="Permanent" />


Beyond Redirection


There are a few important points to keep in mind here. The first being that the redirection should stay in place, you can’t just whack this up and then kill the redirection a week later – this is even truer if you are doing redirections to a new domain. Secondly, if you have links to some high-value pages, and they are moving to another site, the redirection is great, but if you can make changes to those links to point to the new property then you should do that.


Redirect your questions to the comments

If you have any questions then drop a comment below. If you are feeling kind, please share this page with the links below and you can always catch me on Twitter. Now, redirect yourself back to the job you are supposed to be doing! 🙂



6 Responses

  1. hello, firstly sorry for my bad English.
    i need help about something, please if you know, can you teach me, how can i redirect all of “*.html” files to only “/”
    here example:
    DOMAINNAMEURL/post-1.html to post-1/
    DOMAINNAMEURL/post-2.html to post-2/
    DOMAINNAMEURL/post-3.html to post-3/
    i did not write my domain url because of mark spam comments
    DOMAINNAMEURL = vvvvvv-dot-gizlitarif-dot-kom

    1. Hey Turgut, I am a bit rusty with IIS redirects but that should be simple enough and you just need to set the location path to a wildcard like *.html – so… location path=”*.html” and you should be good to go.

  2. Hi,

    Your code for redirection is working perfectly fine, but I have around 2000 pages to redirect and I it stopped to redirect after 1146 th page due to some reason. Can you help me figure out what could have went wrong, or are there any limitation in implementing this.

    1. Hey Dhwani – I believe the max file size for web.config if 250KB so if they will all fit in under that file size then this should be fine. Alternatively you will need to look up redirect maps (Google is your friend here).

      Hope that helps!

  3. I am having an issue with backslash (displaying as \ on Firefox and %5C on Chrome) in homepage URL which is crawled by Google and showing two homepage links in site search results. Is there anyway of getting rid of this backslash in URL and ensuring it only displays and robots crawls https://www.example.com/ only?

    I currently have following versions indexed by Google:

    https://www.example.com/%5C (I cannot find where this is coming from, I have checked all my links and I don’t have any so I am presuming this is coming from an external source)

    And backslash displays as following on the browsers:
    https://www.example.com/%5C on Chrome and
    https://www.example.com/\ on Firefox

    I tried following in robots.txt but it is not working.

    Disallow: \

Leave a Reply

Your email address will not be published. Required fields are marked *

Free Digital Marketing Review

Book a call with Marcus Miller to learn how to generate more traffic, leads and sales.

1. Review your current marketing
2. Identify your key opportunities
3. How to improve results & cut costs!

Put over 20 years of marketing experience to work for your business today.