Quantcast
Channel: ArcaneTek from LowTek
Viewing all articles
Browse latest Browse all 24

Configure IIS to redirect to your preferred URL

$
0
0

The preferred URL for most web sites includes "www." in the beginning of the URL (i.e. http://www.w3.org/). But sites should still work if you go to the URL without the "www." (i.e. http://w3.org/). But in that case, you don't want the user to bookmark the URL without the "www.".

The solution is to make the site without the "www." be a purely redirection-only site that just redirects to the site with "www.". You can do this in IIS by doing the following:

  • Create a new Web Site, right-click it and choose Properties, then navigate to the following dialog boxes and configure the site to use a Host Header that doesn't contain "www.".

  • Switch to the Home Directory tab and make it look like the following:

Explanation:

  • The special $S and $Q syntax is explained here. Basically, it makes it so that whatever the user specifies after the hostname (including file paths and query strings) is included in the redirection to the destination site. (BTW, that page also explained way more advanced and powerful syntax.)
  • When using this special syntax, it makes sense to use "The exact URL entered above" so that IIS doesn't append anything else to the destination URL.
  • "A permanent redirection for this resource" just makes IIS use a 301 Permanent Redirect instead of a 302 Temporary Redirect.

Viewing all articles
Browse latest Browse all 24

Trending Articles