Starting a new website

Posted on : December 02 2023 by andreihetel
IISWeb Tools

From time to time, not too often, I'm doing a new website, usually for a client but this time for myself. WordPress or other content management systems are very popular and represent a quick way of getting things done. Most of the time, a well-known CMS is probably the best solution to build a simple blog. But, the intention is to write about programming, so why not do a custom one, starting from scratch by myself?

Another advantage is that you can choose the technology for building the product, define the goals, and - most importantly - learn some new things along the way.

For this blog, I decided to use Blazor server - a Microsoft technology that allows me to code an entire website without a single line of JavaScript! Isn't this amazing? I was never a fan of JavaScript or JavaScript frameworks, so picking Blazor was a no-brainer. After this long introduction, let's enumerate some suggestions (website hosted on Windows).

SEO - a page must have a single address

What I mean by that is that? For example, the 'About' page can be reached by default using one of the following four addresses: http://www.xiona.org/about, https://www.xiona.org/about, http://xiona.org/about and https://xiona.org/about. In SEO terms, this is not good because the crawler (Google, Bing, etc.) believes there are four different pages instead of only one. Thus, his score is significantly smaller because it's diminished between those versions of the same page.

The first step is to install the module URL Rewrite. It is available on Microsoft's official website at this address.

Next, define site bindings properly to avoid error 404 errors like in the picture below. You should serve SSL and non-SSL versions and addresses with or without www. IIS bindings

The last step is to edit the web.config file to do necessary redirects. In the following example, I choose SSL without www.


<rewrite>
    <rules>
        <!-- Redirect www to non-www and force SSL -->
        <rule name="Force non-WWW" enabled="true" stopProcessing="true">
             <match url="(.*)" />
             <conditions logicalGrouping="MatchAny">
             <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
             </conditions>
             <action type="Redirect" url="https://{C:2}/{R:1}" appendQueryString="true" />
            </rule>
            <rule name="Force HTTPS" enabled="true" stopProcessing="true">
             <match url="(.*)" />
             <conditions logicalGrouping="MatchAny">
             <add input="{HTTPS}" pattern="off" />
             </conditions>
             <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" />
        </rule>
    </rules>
</rewrite>