Thursday, 15 July 2010

Directing all visits to the www subdomain using IIS7

Your SEO champion will no doubt be banging his fists on his desk if you've built a site that allows users to view the same content on http://mysite.com as well as http://www.mysite.com

What he or she will be demanding is that one of them permanently redirects the user (with a 301 status) to the other. So how do you do this? Well, there might be several ways but this is the way I do it. For this example I'm going to be sending visitors from mysite.com to www.mysite.com.

Remove the 'mysite.com' entry from the bindings of your website but keep the 'www.mysite.com' entry. Create a new website and call it 'mysite.com redirect' or something similar. Add a binding to this for 'mysite.com'. This will then accept incoming visits to 'mysite.com'. Now click on the 'HTTP Redirect' icon:

and configure the site to redirect to 'http://www.mysite.com' with a Permanent(301) setting like below:


This will also honour any deep links to your site. For example if a user goes to http://mysite.com/whatever.aspx?whateverParam=whateverValue they will be redirected to http://www.mysite.com/whatever.aspx?whateverParam=whateverValue

UPDATE: on some machines you may not see the 'http redirect' icon. If this is the case go to the IIS section in 'Server Manager' and you'll probably see the role service isn't installed. You can install it easily from here.

Wednesday, 14 July 2010

Solving an updatepanel cacheing problem with SetCacheability

I had an issue today with the contents of an update panel appearing to be cached when they should have displayed a more recent listview of search results. Frustratingly this problem was only happening on the server copy of my site rather than locally.

I resolved the problem with the following code in the page load event:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
UPDATE: ah, so it never worked for Firefox...I went for a solution using a session object instead!

Friday, 2 July 2010

Submitting a sitemap for your Blogger/Blogspot blog

I found this very helpful post on how to submit sitemaps for a blogger blog.

In summary, you need to do the following:

If you have under 500 posts:
http://YOURSITE.blogspot.com/atom.xml?redirect=false&start-index=1&max-results=500

If you have under 1000 posts:
http://YOURSITE.blogspot.com/atom.xml?redirect=false&start-index=1&max-results=500
http://YOURSITE.blogspot.com/atom.xml?redirect=false&start-index=501&max-results=1000

If you have under 1500 posts:
http://YOURSITE.blogspot.com/atom.xml?redirect=false&start-index=1&max-results=500
http://YOURSITE.blogspot.com/atom.xml?redirect=false&start-index=501&max-results=1000
http://YOURSITE.blogspot.com/atom.xml?redirect=false&start-index=1001&max-results=1500