homepage Welcome to WebmasterWorld Guest from 54.227.20.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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 301 redirect in IIS6.0
Kris999

5+ Year Member



 
Msg#: 3951672 posted 5:12 pm on Jul 13, 2009 (gmt 0)

Hi,

I'm using Windows server(IIS 6.0) and I would like to redirect,

http://example.com
http://example.com/default.htm
http://www.example.com/default.htm

to

http://www.example.com

I searched for the procedure. But, I didn't get perfect solution for it.

So, Please let me know the procedure to do it.

Thanks in advance your replies.

 

marcel

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3951672 posted 5:48 pm on Jul 13, 2009 (gmt 0)

The best option would be to use something like ISAPI Rewrite, is it possible to install this (or get it installed) on the server?

Another option, if you have access to the IIS control panel you can set up two websites, one with the host header www.example.com and one without the www, and then redirect the non-www to the www site. (check the permanent redirect checkbox).

This won't fix the www.example.com/default.htm problem though.

For this, one option is to map the .htm extension to .asp (or .aspx) in the Application Configuration of IIS control panel, and redirect with a simple 301 script in the page itself. (make sure that default.htm is no longer you default document though)

ie. rename your home page to something else, ie. index.htm, make index.htm your default document and remove default.htm from the default document list.

Create a default.htm file and add the following code:
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.example.com/"
%>

Or, you could upgrade to IIS7 and use the IIS7 rewrite module.

Kris999

5+ Year Member



 
Msg#: 3951672 posted 10:45 pm on Jul 13, 2009 (gmt 0)

Thanks for your reply.

Whether there is any chance of getting penalized in search engines for using script in the page?

marcel

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3951672 posted 7:58 am on Jul 14, 2009 (gmt 0)

Whether there is any chance of getting penalized in search engines for using script in the page?

This shouldn't be a problem at all (as long as it's a 301 redirect). But try to make sure that no other pages are directly linking to the 'old' default.htm page, link to the new location.

malky800

5+ Year Member



 
Msg#: 3951672 posted 8:38 pm on Jul 21, 2009 (gmt 0)

I am having the same issue and just downloaded isapi rewrite. I never had any experiance with pearl though.
I am looking to redirect
http://www.example.com/index.htm
to
http://www.example.com/
Do you know the appropriate coding to do this?
I have seen quite a few different ways but i want to make sure I'm doing it right.

Thanks

[edited by: Ocean10000 at 12:13 am (utc) on July 22, 2009]
[edit reason] Examplified URLS [/edit]

marcel

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3951672 posted 2:43 am on Jul 22, 2009 (gmt 0)

here is one way:
RewriteCond Host: www\.example\.com
RewriteRule /([^?.]+)/index\.htm http\://www.exampla.com/$1/ [I,RP]

pageoneresults

WebmasterWorld Senior Member pageoneresults us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3951672 posted 3:40 am on Jul 22, 2009 (gmt 0)

ISAPI_Rewrite is by far the most robust rewriting tool for IIS, nothing compares, not even IIS 7 enhancements.

Here are a list of basic rules that we use with ISAPI_Rewrite 2.0 and the .ini method. There is a 3.0 version using .htaccess which we use also.

[ISAPI_Rewrite]

# Webresource file for ASP.NET
RewriteRule /(webresource.axd.*) /$1 [I,L]

# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:\.ini¦\.parse\.errors) / [F,I,O]

# Block external access to the Helper ISAPI Extension
RewriteRule .*\.isrwhlp / [F,I,O]

# Exclude anything that starts with _ for FrontPage extensions, if enabled.
# e.g. _derived, _private _vti_cnf
RewriteRule (.*/_.*) $1 [I,L]

# Place any exceptions here.
# Example here showing to execute any images, css, js, as is.
RewriteRule /(js¦nav¦images)/(.*) /$1/$2 [I,L]
RewriteRule (.*)(\.css¦\.js) $1$2 [I,L]

# Set different robots.txt for different protocol.
# You need to create a robots.https.txt (update this to point to the correct script)
RewriteCond %HTTPS on
RewriteRule /robots.txt /robots.https.txt [I,O,L]

# Move anything from non- www.example.com -> www.example.com
# e.g. example.com -> www.example.com
RewriteCond %HTTPS off
RewriteCond Host: (?!^www.example.com)(.+)
RewriteRule /(.*) http\://www.example.com/$2 [I,RP]

# Same as above but for SSL.
RewriteCond %HTTPS on
RewriteCond Host: (?!^www.example.com)(.+)
RewriteRule /(.*) https\://www.example.com/$2 [I,RP]

# Add trailing slash for folders.
RewriteRule ([^.?]+[^.?/]) [$1$2...] [I,RP]

# Convert all upper case to lower case.
# If you are using http post, you must make sure everything in the URI are lower case.
# Otherwise, the redirect will lose the form values.
RewriteCond URL ([^?]+[[:upper:]][^?]*).*
RewriteHeader X-LowerCase-URI: .* $1 [CL]

RewriteCond %HTTPS on
RewriteCond X-LowerCase-URI: (.+)
RewriteRule [^?]+(.*) https\://www.example.com$1$2 [I,RP]

RewriteCond %HTTPS off
RewriteCond X-LowerCase-URI: (.+)
RewriteRule [^?]+(.*) http\://www.example.com$1$2 [I,RP]

# If you have any folders/files that need to be SSL enabled, list them here.
# Redirect all the following folders to SSL if it's not SSL currently.
RewriteCond %HTTPS off
RewriteRule /(client¦admin¦contact)/(.*) https://www.example.com/$1/$2 [I,RP]

# This line will execute the code since it passed all the above checks and it's still SSL.
# The matching expression should be the same as last line.
RewriteCond %HTTPS on
RewriteRule /(client¦admin¦contact)/(.*) /$1/$2 [I,L]

# This will force ANY https:// to http: if they are not in the last rule above.
RewriteCond %HTTPS on
RewriteRule (.*) http://www.example.com$1 [I,RP]

# This will 301 all index. requests to the root level for that directory.
RewriteRule (.*/)index\.asp $1 [I,RP,L]

# This will 301 old URI to new URI.
RewriteRule /sub/oldfile.htm http://www.example.com/sub/newfile.asp [I,O,RP,L]


marcel

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3951672 posted 4:39 am on Jul 22, 2009 (gmt 0)

Thanks pageoneresults, I searched for one of your old posts with this info, but couldn't find it.

malky800

5+ Year Member



 
Msg#: 3951672 posted 2:44 pm on Jul 22, 2009 (gmt 0)

Thanks Marcel and Pageoneresults.
I've seen a lot of examples that have [R=301] is that the same as RP as i'm interested in doing a 301. Also what's the differance between:

RewriteCond Host: www\.example\.com
RewriteRule /([^?.]+)/index\.htm http\://www.exampla.com/$1/ [I,RP]
and

# This will 301 all index. requests to the root level for that directory.
RewriteRule (.*/)index\.asp $1 [I,RP,L]


bwnbwn

WebmasterWorld Senior Member bwnbwn us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3951672 posted 4:39 pm on Jul 24, 2009 (gmt 0)

RewriteCond Host: www\.example\.com
RewriteRule /([^?.]+)/index\.htm http\://www.exampla.com/$1/ [I,RP]

the above sends header 301 response and what page the 301 is going to.

RewriteRule (.*/)index\.asp $1 [I,RP,L] ]

header response 301 and not were the page is being redirected.

The first one is the best.

After much trial and error I finally found one that worked for me for an htm site. I think I tried the 1st one above and it didn't work on my server.

rewritecond %{the_request} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.htm\ HTTP/
RewriteRule index\.htm$ http://www.example.com/%1 [R=301,L]\

Kris999

5+ Year Member



 
Msg#: 3951672 posted 6:52 pm on Jul 27, 2009 (gmt 0)

Hi marcel,

I tired the 2nd option,

"if you have access to the IIS control panel you can set up two websites, one with the host header www.example.com and one without the www, and then redirect the non-www to the www site. (check the permanent redirect checkbox)."

But, I was not able to redirect, it was just looping. Whether I have to do anything with setting?

bwnbwn

WebmasterWorld Senior Member bwnbwn us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3951672 posted 9:08 pm on Jul 27, 2009 (gmt 0)

Kris999 did you delete the non www name from IIS you will see it by selecting the website in IIS properities then advanced.
Delete the one you want to redirect.

Then in IIS select add website add the correct IP address and the non www I always name it "example2" so I know what it is for one the path this does not matter you can select anything.

After that is set up then right click the new site you just did select homepage and select redirect check the box and add the www.example.com
[webmasterworld.com...]
More help if you need it

Kris999

5+ Year Member



 
Msg#: 3951672 posted 9:26 pm on Jul 27, 2009 (gmt 0)

This is what I have done,

I have example.com in my IIS server, So, I created www.example.com website with same source.
I right clicked option of example.com and redirected permanently to www.example.com.

I have not deleted non www site.

Looking forward for your reply.

bwnbwn

WebmasterWorld Senior Member bwnbwn us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3951672 posted 9:37 pm on Jul 27, 2009 (gmt 0)

look in the example.com under advanced and see if it www.example.com is still there if so delete it.

Also did you map the correct path to the site when you added the www.example.com in IIS

Kris999

5+ Year Member



 
Msg#: 3951672 posted 10:01 pm on Jul 27, 2009 (gmt 0)

Thanks a lot..
Now deleted it and its working great.

bwnbwn

WebmasterWorld Senior Member bwnbwn us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3951672 posted 11:28 pm on Jul 27, 2009 (gmt 0)

good glad to be of assistance those little things we "all" over look that freeks us out

PS make sure u check to make sure it is a true 301 google "header check" and put the non www in there and u should see the correct path

Kris999

5+ Year Member



 
Msg#: 3951672 posted 11:46 pm on Jul 27, 2009 (gmt 0)

I checked with "header check" tool in few sites.
Its working fine. Thanks for your assistance.

bwnbwn

WebmasterWorld Senior Member bwnbwn us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3951672 posted 5:05 pm on Jul 28, 2009 (gmt 0)

just a note kris999 that didn't fix the question you asked it just fixed the www and non www issue.

you can't301 the www.example.com/index.htm to www.example.com/ in IIS needs to be done another way as described above.

malky800

5+ Year Member



 
Msg#: 3951672 posted 5:46 pm on Aug 5, 2009 (gmt 0)

I would like to test the page that I redirected (index.html -root) through the isapi rewrite filter using google website optimizer. Would the redirect conflict with the optimizers own redirection?

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