homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

How to set up a 301 redirect
Easy instructions please

 10:08 am on May 14, 2004 (gmt 0)

Iím trying to create a 301 redirect from [mysite.com...] to [mysite.com...]
How do I do this?

IES spy sayís Iíve got to change the IP address of mysite.com and then use code to redirect to www.mysite.com. Is this the only way yo do it in IIS5? That sounds a bit scary, changing the I.P address..

Can I do this DNS, i have full access to my DNS?

I really need a straight easy to follow explanation on this.
Anyone help please?



 12:32 pm on May 14, 2004 (gmt 0)

Just create a website with a default.asp file with script:


Don't think it matters where the site is hosted.


 2:12 pm on May 14, 2004 (gmt 0)

Response.Redirect() is actually a 302 (Temporary Move).

You need to do this for a 301:

Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.example.com/yourpage.asp"



 4:52 am on May 15, 2004 (gmt 0)

Not sure if I'm understanding this correctly.


Just create a website with a default.asp file with script:

So i have to change the IP address? Not really viable as the site is in all search engines, a new IP will course alsorts of problems with them?
This is the first time i've had to set this up and if the clients website has to start a fresh in the search engines i'm hung, drawn and diced into tiny pieces.
Is there no other way i can create this?


 4:21 pm on May 15, 2004 (gmt 0)

No, you don't have to change the IP address. On any page that you want to redirect, put the code I posted above at the very top of the page. replace "example.com/yourpage.asp" with your site/page you want to redirect to.



 4:10 am on May 16, 2004 (gmt 0)

I think we've lost focus of the original question, or i'm being very stupid. Sorry i am a beginner.

I know how to do a redirect in code, i am asking to do a redirect from example.com to www.example.com, at any stage

The DNS points both example.com and www.example.com to the same I.P address in IIS. To use this code, as your correctly mention above, i would need to set up a new 'dummy' website in IIS with a new I.P address, so when someone omits the www it will go to this new site and then use the code mentioned to redirect to the correct www site. This as i see it, needs a new I.P address for a 'dummy' website, which i desperatly want to avoid. So can this be done without a 'dummy' website?


 4:51 pm on May 16, 2004 (gmt 0)

Are you wanting to do a redirect if the user or bot goes to whatever.com rather than www.whatever.com? All you need to do is provide an include in every page that checks SERVER_NAME server variable and if it finds no 'www.' does the 301 with the headers mentioned above.

Have I understood the problem correctly?



 5:08 am on May 17, 2004 (gmt 0)

Yes thatís what I want to do but unfortunately Iíve got 20,000+ pages on the site.
Placing the code on every page isn't really an option. I need universal way of making this happen.


 6:45 am on May 17, 2004 (gmt 0)

If it is a dedicated/co-lo server you can add a new site to IIS and set the host header URL in the settings. Set that site to have a permanent redirect to the www. version. You do not need a new IP for that, they determine which is which via the url the user uses (its a http 1.1 thing).


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