• 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: , , ,

Tuesday, 15 January 2008

ASP and 30x redirects for SEO

One of the common things I come across when building websites is the lack of understanding for SEO when you are porting to a new site.

One recent site I've just finished meant porting a site from classic ASP 3.0 to ASP.net and how to point redirects to the new pages to maintain the SEO rankings. Well the obvious answer is a 301 redirect. But how?

Well there are many ways on an IIS box but the basic way to point ASP (classic) pages is to have a global.asa AS WELL AS a global.asax. The global.asa will serve ASP (classic) and the global.asax will serve the ASP.net pages... Therefore we can simply put our redirect code into the global.asa and point our .asp files to their new .aspx conterparts...

If Request.ServerVariables("PATH_INFO")= "/default.asp" Then
If Request.ServerVariables("QUERY_STRING")="" Then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.mydomain.com/"
Else
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.mydomain.com/?" &
Request.ServerVariables("QUERY_STRING")
End If
End if


I've added the check for querystring variables in case you wanted to pass any tracking or like URL variables to your new page but you can customise to suit your needs.

Labels: , , , , ,

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