DiscountASP.NET Forums

Go Back   DiscountASP.NET Forums > Site Programming, Development and Design > Windows 2008 / IIS 7

Reply
 
Thread Tools Search this Thread
Old 11-02-2009, 09:54 AM   #1
Will1968
 
Join Date: Dec 2008
Posts: 31
HTTP Redirect and 301 redirects to ensure that the URL is frefixed with www

Hi,

I want to ensure that crawlers and vsitors arriving at my site always use a url prefixed with www e.g. http://www.yourdomain.com and not http://yourdomain.com.

I thought I could do this using the HTTP Redirect module in the IIS Manager.

However when I set it up my web pages would not load.

I followed the example in this link and set everything as follows...

Redirect requests to this location: http://www.yourdomain.com

All other boxes were unticked

Status code: 301

http://www.trainsignaltraining.com/w...on/2008-03-27/

What did I do wrong?

I am using IIS7

Will
Will1968 is offline   Reply With Quote
Old 11-02-2009, 10:51 AM   #2
bruce
DiscountASP.NET Staff
 
Join Date: Jan 2003
Posts: 5,673
you don't want to use redirect because you'll be redirecting back to itself and causes a loop.

You'll want to use the URLRewrite module to handle 301 redirect.
__________________
Bruce

DiscountASP.NET
bruce is offline   Reply With Quote
Old 11-02-2009, 01:34 PM   #3
Will1968
 
Join Date: Dec 2008
Posts: 31
Thanks for the pointer.

I found some great resources on this subject and setting up some basic url rewrites to ensure SEO optimisation on urls.

http://blogs.msdn.com/carlosag/archi...ewriteSEO.aspx

and

http://ruslany.net/2009/04/10-url-re...ps-and-tricks/

Everyone who is serious about SEO and maximising backlink value should read these links.
Will1968 is offline   Reply With Quote
Old 11-04-2009, 08:26 AM   #4
Will1968
 
Join Date: Dec 2008
Posts: 31
I thought I had a solution but I seem to postback onto myself when i click on a asp button or link button. I don't have a problem with a standard href link.

This is what I have for the url rewrite in the webconfig.....

<rule name="Default Document" stopProcessing="true">
<match url="(.*)default.aspx" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>

taken from http://blogs.msdn.com/carlosag/archi...commentmessage

Will

Last edited by Will1968; 11-04-2009 at 08:28 AM. Reason: typo
Will1968 is offline   Reply With Quote
Old 11-04-2009, 10:12 AM   #5
bruce
DiscountASP.NET Staff
 
Join Date: Jan 2003
Posts: 5,673
Try switching it to rewrite action.
__________________
Bruce

DiscountASP.NET
bruce is offline   Reply With Quote
Old 11-05-2009, 04:34 AM   #6
Will1968
 
Join Date: Dec 2008
Posts: 31
I tried that, just changing it to this...

<rule name="Default Document" stopProcessing="true">
<match url="(.*)default.aspx" />
<action type="Rewrite" url="{R:1}" redirectType="Permanent" />
</rule>

It did not seem to do anything.

The redirect (using my intial rule) did not work when the following code was run (or possibly not run) after clicking an asp link button on the default.aspx page

Protected Sub cmdShoppingBasket_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdShoppingBasket.Click
Response.Redirect("~/Shopping-Basket.aspx")
End Sub

Its not a problem when there is bog standard href.

It seems to me the problem occurs when on the default.aspx page there is a postback onto itself which then stops any subsequent code being run.

Any ideas?
Will1968 is offline   Reply With Quote
Old 11-06-2009, 05:12 PM   #7
Aristotle
DiscountASP.NET Staff
 
Join Date: Mar 2004
Posts: 549
Try this:

Code:
<rule name="Redirect to WWW" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^(www\.)(.*)$" />
        <add input="{HTTP_HOST}" pattern="(.*)" />
    </conditions>
    <action type="Redirect" url="http://www.{C:0}/{R:1}" redirectType="Permanent" />
</rule>
__________________
Aristotle

DiscountASP.NET
www.DiscountASP.NET
Aristotle is offline   Reply With Quote
Old 11-07-2009, 01:12 AM   #8
Will1968
 
Join Date: Dec 2008
Posts: 31
Hi,

Thanks for the reply.

The code you have suggested just appends www to the fromt of a non www url.

The issue I have is that I want to remove the default.aspx at the front of my homepage.

Will
Will1968 is offline   Reply With Quote
Old 11-11-2009, 06:59 PM   #9
Aristotle
DiscountASP.NET Staff
 
Join Date: Mar 2004
Posts: 549
Quote:
Originally Posted by Will1968 View Post
Hi,

Thanks for the reply.

The code you have suggested just appends www to the fromt of a non www url.

The issue I have is that I want to remove the default.aspx at the front of my homepage.

Will
I thought you still haven't resolved your original issue, which was to redirect to www. So the issue that you're having is that when someone enters your domain name it goes to the default.aspx?
__________________
Aristotle

DiscountASP.NET
www.DiscountASP.NET
Aristotle is offline   Reply With Quote
Old 11-12-2009, 12:23 AM   #10
Will1968
 
Join Date: Dec 2008
Posts: 31
Ah sorry I now realise that the original question has morphed into a different one.

I also posted on the IIS forum and got this reply...

http://forums.iis.net/p/1162366/1924045.aspx#1924045

Apparently there is no way round my issue.
Will1968 is offline   Reply With Quote
Reply

Bookmarks

Tags
301 redirects, http redirect

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect HTTP to HTTPS - PLEASE Help NewMind Windows 2008 / IIS 7 3 06-22-2008 03:28 AM
redirect http to https sushantone ASP.NET 2.0 3 04-04-2007 04:29 AM
Need a way to 301 redirect http://mysite.com/index.htm to http://www.mysite.com/index.htm mluirette Search Engine/Directory Marketing 40 03-27-2007 10:15 AM
HttpModule ensure pages have AJAX ScriptManager wisemx ASP.NET 2.0 0 01-20-2007 12:59 PM
Redirect from http://myDomain.com to http://www.myDomain.com bruce Hosting Services / Control Panel 1 06-07-2006 12:47 PM


All times are GMT -8. The time now is 04:39 AM.


vBulletin ©Jelsoft Enterprises Ltd.