• Client login
  • Work for us

All the latest from the team...

Wednesday, 6 February 2008

Simple IIS 301 redirects

One of the common requests I get is to setup 301 redirects when porting to a new site. There are really simple ways to do this on an Apache based server but for IIS on Microsoft platforms it's not as easy as having a .htaccess file and you need to know a few things about IIS operates in order to do this.

For example if you can redirect a directory on IIS you can do really simply by pointing the directory at a new URL. Simply right-click on the directory in IIS and select properties to be presented with the following screen:



Simply select the "Directory" tab and the "redirect to a url" option then type the url into the "Redirect to:" box. You can even pass over querystring parameters (let's say for tracking or the like) by adding $Q to the end of the URL.

For example:

If the virtual directory that is mapped to the following Web site:

http://www.mydomain.com/products

is configured to be redirected to the following exact URL:

http://www.myNEWdomain.com/products$S$Q

A new request for the following URL:

http://www.mydomain.com/products/File.asp?var1=5&var2=6

Would be redirected automatically to the following URL:

http://www.myNEWdomain.com/products/File.asp?var1=5&var2=6


For more information on what variables you can pass check out the IIS documentation at: IIS Docs

Or give us a shout at Code Required as we'd be only to glad to help!

Also check out our article about porting an ASP (classic) site to ASP.net and how you can setup 301 redirects really easily!

Labels: , , ,

1 Comments:

Anonymous Mike Irving said...

Another great way of performing redirects is to specify a custom 404 page, then check the incoming filename against a list of old file names.

For all pages that you need to redirect, you can then redirect using a 301 header, and if not simply return a 404 page with a 404 header.

i.e. you could redirect index.html to homepage.asp and contact.php to new-contact.asp, with 301 redirects, whilst still returning a 404 page for yourdomain.com/made-up-page.html

This method is more flexible and does not require access to IIS. Most hosting firms will allow you to setup custom error pages via their control panel systems.

Mike Irving - Web Developer

May 07, 2008 5:46 PM  

Post a Comment

<< Home

RSS feed ATOM feed Add to Technorati Favorites View Jon Harvey's profile on LinkedIn