![]() |
|
|||||||
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
|
#2 |
|
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 |
|
|
|
|
|
#3 |
|
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. |
|
|
|
|
|
#4 |
|
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 |
|
|
|
|
|
#5 |
|
DiscountASP.NET Staff
Join Date: Jan 2003
Posts: 5,673
|
Try switching it to rewrite action.
__________________
Bruce DiscountASP.NET |
|
|
|
|
|
#6 |
|
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? |
|
|
|
|
|
#7 |
|
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>
|
|
|
|
|
|
#8 |
|
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 |
|
|
|
|
|
#9 |
|
DiscountASP.NET Staff
Join Date: Mar 2004
Posts: 549
|
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?
|
|
|
|
|
|
#10 |
|
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. |
|
|
|
![]() |
| Bookmarks |
| Tags |
| 301 redirects, http redirect |
| Thread Tools | Search this Thread |
|
|
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 |