Search Engine Friendly 301 Redirects Without Touching IIS
Most websites are configured to serve the same content (the home page) for www.mysite.com and mysite.com, but technically a web server could return two different pages for both urls. Why is this important? It could hurt your ranking and you are making Google and other search engines guess what page to index if there are numerous choices to choose from. Google calls this process of selecting one URL over another “canonicalization.”
So what can you do to ensure that Google picks your preferred URL?
For one, be consistent when forming your internal links. In other words, “don’t make half of your links go to http://example.com/ and the other half go to http://www.example.com” as renowned Google engineer Matt Cutts points out.
Secondly, implement a 301 permanent redirect from the non-www version of your site to the www version or vice versa, which is what I would like to focus on in this post.
While the web is full of examples on how to setup a 301 redirect on the all so popular Apache web server, IIS walkthroughs are rather scarce. And even if you do find them, most are on-page scripts that won’t solve the www vs. non-www dilemma and won’t work in DNN’s “one page” model.
Let’s say you want to permanently redirect the non-www version of your asp.net based website to the www version. The most straightforward way to do this in IIS is to actually set up two IIS web sites for your web site. Sounds confusing? See the screenshots below.

Set up your www version as you would any other website. Include the www portion when entering the host header value and point to the DNN web files on your server.

Now create a second IIS website and enter the host header value without www and point “the content for this resource” to your www URL like this:

Notice the two variables ($S$Q) at the end of the URL, which ensure that all other pages besides the home page redirect correctly as well. Also make sure to have “the exact URL entered above” and “a permanent redirection for this resource” checked.
If everything went well, your browser will now redirect mysite.com to www.mysite.com. Another option is to install a component such as ISAPI_Rewrite, which emulates Apache's mod_Rewrite for IIS, but that’s food for another post.
Both of these approaches obviously require full IIS access, which is not an option in a shared hosting environment. But even with unrestricted IIS control, if I were to set up two IIS websites for every client on my web server, IIS would get messy very soon.
This leads us to the most elegant solution that does not involve IIS at all - UrlRewritingNet.UrlRewrite. With this open source component (HTTP module on steroids I guess) you upload a .dll into the bin directory of your website and add a few lines to web.config and you are done. Now you have a search engine safe redirect from mystite.com to www.mystite.com or vise versa without touching IIS. I’ve prepared a DNN 4.5.1 web.config with all three UrlRewritingNet.UrlRewrite settings in place for your reference. Download it here.
Best of all, this only scratches the surface of what UrlRewritingNet.UrlRewrite is capable of. With full regular expression support and the ability the plug in your own provider, the “rewrite opportunities” are endless. As an example, I’m currently trying to figure out how to shorten my permalink URLs, removing the tabid/53/articletype/articleview/articleid/xx/ part.
In closing, whatever method you prefer, make sure your redirects are configured correctly (301 and not 302) with a tool such as the Search Engine Friendly Redirect Checker.
As always, I appreciate your comments and if you like this post, then consider subscribing to my full feed RSS.
Comments are closed