Forum Moderators: open

Message Too Old, No Replies

non-www to www redirection on IIS

         

cybotron

8:31 am on Sep 16, 2011 (gmt 0)

10+ Year Member



Hi Guys,

I have having some problems redirecting non-www to www on an IIS webserver.

The website is on a shared server and i have contacted my web hosting company but they have said that they are not willing to configure it.

They have said that I can use an ASP redirect script to do this but how can I use ASP when I am trying to redirect mydomain.com to www.mydomain.com.

The only way is through IIS right?

Thanks in advance.

Cy.

g1smd

8:36 am on Sep 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can do it in ASP.

Detect if requested URL does not begin www.example.com and use response.header (or whatever it is called) to send a redirect back out.

You can also do it in the server configuration. Method varies depending on which version of IIS you use.

There are several previous threads with the code for every method.

cybotron

8:41 am on Sep 16, 2011 (gmt 0)

10+ Year Member



Thanks for the reply.

Where do i place the ASP code? On the index.html file or create a new file? Please can you show me an example of the code if possible.

Thanks again.

g1smd

10:21 am on Sep 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You place the ASP code at the very top of every page that might be requested with the wrong domain name.

As for code, use the forum search to find hundreds of previous examples.

cybotron

11:41 am on Sep 16, 2011 (gmt 0)

10+ Year Member



Thanks but how can i put a redirect ASP code on a non-www (example.com)?

g1smd

11:53 am on Sep 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You put the code on page6 and the code says "if the requested URL was example.com/page6 then redirect to www.example.com/page6".

If the requested URL was example.com/page6 then obviously the redirect code doesn't run and instead the real page6 content is served.

cybotron

12:11 pm on Sep 16, 2011 (gmt 0)

10+ Year Member



At the moment whats happening is if you type in example.com then that page is served and then if you type in www.example.com then that page is served which is the same as example.com and which is duplicate content right?

How can i redirect example.com to www.example.com?

Thanks again and sorry to be a pain

g1smd

12:15 pm on Sep 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I thought I already explained it. Which bit didn't you understand?

cybotron

12:36 pm on Sep 16, 2011 (gmt 0)

10+ Year Member



What i am trying to say is that how can i put a ASP redirect code on example.com so it would redirect to www.example.com, as i am using an index.html file for my home page?

Sorry to be so confusing...

lucy24

8:10 am on Sep 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Holy ###. g1, are you saying he'd have to put in this bit of code at the top of each and every individual page? Or should I not be trying to understand this stuff at 1AM?

g1smd

8:36 am on Sep 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, if you want to do this in ASP it needs to be at the top of the page.

Of course, in a fully dynamic site this would mean adding once it to just one file.

Ocean10000

3:26 pm on Sep 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There is another way depending on the version of IIS you are running.

If you are using IIS 7 or later this add-on will work for the whole site. It is configurable via the IIS management tool once installed.
[iis.net...]

higgins

6:31 pm on Oct 5, 2011 (gmt 0)

10+ Year Member



Hey guys, I've never worked with ASP before and am trying to configure a redirect using Server.Transfer instead of the individual page redirect. If anyone can help me redirect my /index.asp page to the root using a Server.Transfer method, that would be greatly appreciated.
Below is the code I've found if you want to use Response.Redirect on an individual page level. I haven't used it, so I can't troubleshoot or assist in implementation.
<%@ Language=VBScript %>
<%
' Permanent redirection
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.example.com/"
Response.End
%>

Ocean10000

4:15 am on Oct 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What is your goal in using Server.Transfer instead of the Response redirect?

Server.Transfer will not change the displayed URL in the browser.

Reference:
Server.Transfer Method [msdn.microsoft.com]

dukelips

9:13 am on Feb 3, 2012 (gmt 0)

10+ Year Member



can it be done by create two sites in iis. moving non www sites to www