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/windows-server-2008-http-redirection/2008-03-27/ What did I do wrong? I am using IIS7 Will
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.
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/archive/2008/09/02/IIS7UrlRewriteSEO.aspx and http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/ Everyone who is serious about SEO and maximising backlink value should read these links.
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/arch...iteSEO.aspx?CommentPosted=true#commentmessage Will
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?
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>
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?
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.
i know its an old thread, but if anyone else has got this problem when using default documents rewrite rule, just add this to your master pages .cs file: protected void Page_Load(Object sender, EventArgs e) { form1.Action=Request.RawUrl.Replace("default.aspx", ""); ... you must have framework v3.5 SP1 installed for form action property (DASP has it, but you may not at home/work), it prevents the old url appearing in address bar when you do postbacks to the same page (no matter what rewrite rule), and the replace part is there so that default.aspx pages dont postback onto themselves with default documents rewrite rule...
Hi, Thanks for the reply. Good idea. Could be a useful approach for a other yet unthought of scenarios. Thanks, Will