Implementing Redirects with IIS and Server-Side Scripting

- March 20, 2007

In this last post about SEO friendly redirects I will be covering IIS, ASP, and PHP redirects. In the first post I explained the differences between a 301 and 302 redirect and also gave some examples of when you would use them. The second post discussed actually implementing those redirects with the Apache web server. Please read my previous posts if you don’t understand what an SEO friendly redirect is.

Today I will talk about implementing 301 redirects on IIS. I will briefly discuss
server-side scripting and how it can be used to perform redirects as well.

In IIS, the standard way to do a 301 redirect is to use the Internet Services Manager tool. This can by found in the control panel under administration tools.

In the Internet Services Manager, right click on the file or folder you wish to redirect and select properties. Once the dialog window opens, select the radio titled “a redirection to a URL”. Enter the URL you wish to redirect to and then check “The exact url entered above” as well as the option “A permanent redirection for this resource”. If you leave the last option out you will be performing a 302 redirect instead of a 301 redirect. The default is off so make sure you check this option before you apply the changes and close the dialog window.

This is a very simple redirect to perform if you have physical or remote access to your Windows based web host.

If you only have FTP access to your web host and you are using a server-side scripting language you can also put a few lines of code directly in the .asp or .php file(s) you wish to redirect. Below are some code examples of these redirects in ASP, .NET, and PHP. Also note that these snippets of ASP and .NET code could also go in your global.asa or global.asax files if you are familiar with those.

Code Examples Below.

To perfom a 301 redirect using ASP

Response.Status="301 Moved Permanently"
Response.AddHeader "Location", ""

To perfom a 301 redirect using .NET

private void Page_Load(object sender, System.EventArgs e){
Response.Status = "301 Moved Permanently";

To perfom a 301 redirect using PHP

header("HTTP/1.1 301 Moved Permanently");

Just like in the previous posts the only difference between the 301 and 302 redirect code is the added option which says that the redirect is to be a 301. The defaults are again 302 if you leave that option out. Here are 2 examples of 302 redirects below.

To perfom a 302 redirect using PHP


To perfom a 302 redirect using ASP

Response.Redirect ("");

If you missed my last two posts on SEO redirects here are the links again.
Part 1. When and why to use 301 or 302 redirects
Part 2. Implementing 301 and 302 Redirects on Apache

Posted in: Tips & Tools

Comments are closed at this time.

© 2016 MoreVisibility. All rights reserved