homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

Another non www to www redirect question

 9:38 am on Apr 6, 2010 (gmt 0)


I am not a coder, but can get away with copying code into the .htacess file with php.

But now I have been asked to look after asp site, that is on a shared server. so looking for code to redirect non www to www and index.asp to / for seo reasons.

I have found a few posts regarding code and most are the same code or very similar to that below. But I can't get any of these similar examples to work.

So my questions are?
Do I put this code at the very top of the index.asp file, before the doctype command? If not, then that is probably what I am doing wrong.

The code below does not work on this shared server from a well know web host, has anyone had a similar issue and is there something I should do with the hosting?

<rule name="Redirect to www" stopProcessing="true">
<match url=".*" />
<add input="{HTTP_HOST}" pattern="^example.com$" />
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />




 10:03 am on Apr 6, 2010 (gmt 0)


Found the solution to redirect non www to www but still having issues with index.asp redirecting to root.

Because on our shared server the homepage script is set as index.asp, when ever we redirect to root, it creates a loop back to index.asp over and over again.

So the next question, is how to remove this loop, or isthere redirects without loop?



 10:06 am on Apr 6, 2010 (gmt 0)

Hi flanok,

The code you have posted belongs in the web.config file, but it will only work with IIS7.x which has the URL Rewrite Module [learn.iis.net] installed. You can ask your host if this is the case.

Otherwise you will need a product like ISAPI Rewrite installed on the server.


 10:20 am on Apr 6, 2010 (gmt 0)

Hi thanks for the reply

the code we have found that works with www but not index.asp is

If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
if Request.ServerVariables("URL") = "/index.asp" then
say = ""
say = Request.ServerVariables("URL")
end if
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www."& Request.ServerVariables("HTTP_HOST")& Request.ServerVariables("REQUEST_URI")& say
End if

We are wokinging with ii6

It works with www to non www but not the index.asp, which just loops with the www version of the index.asp but works fine with the non www version of index.asp.

The problem we have is google has picked up the index.asp within its index and so need a redirect not to have duplicate content issues.

Can we install ISAPI Rewrite on a shared server, or is this something that comes with hosting?




 10:53 am on Apr 6, 2010 (gmt 0)

The only way I know of redirecting from index.asp to root on IIS6 is to use ISAPI_rewrite (or a tool like it).

You will need to ask your host to install this for you, unfortunately many will not do this.


 10:55 am on Apr 6, 2010 (gmt 0)

Ok thanks

In short, with a shared server you can't redirect index to root


 12:22 pm on Apr 6, 2010 (gmt 0)

In short, with a shared server you can't redirect index to root

Well, you can if your host is agreeable to installing extra software, and with IIS7 it's much easier, but in essence most host won't help you here.

One option, which is a bit of a hack is to change your default document to something else, say myIndex.asp

Rename your Index.asp to this, and create a new Index.asp which redirects to the root.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved