Forum Moderators: open

Message Too Old, No Replies

URL Canonicalization for Windows IIS

         

raj1094

1:08 pm on Dec 15, 2009 (gmt 0)

10+ Year Member



Dear Webmasters,

Recently i have register a domain and space in Go daddy under "Windows Plan".

Now my question is I want to solve "URL Canonicalization Issues for my domain".

What are steps to do to avoid the "canonicalization problem"?

I know to solve this issues by creating a permanent redirection using 301 redirect in .htaccess for Linux server.

But how to do with Windows Server.

Thanks in Advance

phranque

12:25 am on Dec 16, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



ISAPI_Rewrite is the equivalent for IIS

marcel

6:00 am on Dec 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If GoDaddy don't have ISAPI_Rwrite on their servers, you can ask if they have the IIS7 Rewrite Module [iis.net] installed.

If this is also not the case you can implement your own simple redirect method within the BeginRequest method in the Global.asax.

marcel

8:23 am on Dec 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is a simple example of doing it from the Global.asax file:

void Application_BeginRequest(object sender, EventArgs e)
{
if (!HttpContext.Current.Request.Url.AbsoluteUri.ToLower().StartsWith("http://www."))
{
string newUrl = HttpContext.Current.Request.Url.AbsoluteUri.ToLower().Replace("http://", "http://www.");
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", newUrl);
}
}

phranque

10:14 am on Dec 16, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



how do you solve the default directory index document canonicalization problem without ISAPI_Rewrite?
http://example.com/index.html

marcel

11:29 am on Dec 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how do you solve the default directory index document canonicalization problem without ISAPI_Rewrite?

With the IIS7 rewrite module:

<rule name="Default Document" stopProcessing="true">
<match url="(.*)default.aspx"/>
<action type="Redirect" url="{R:1}" redirectType="Permanent"/>
</rule>

dstiles

11:41 pm on Dec 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A simple way on any system is the canonical tag. Although it's better if you can get it right in the source code, you cannot force linking sites to get it right so I use both.

<link rel="canonical" href="http://www.example.com/" />

The href can be any reasonable url including querystrings.

phranque

2:20 am on Dec 17, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the canonical link element is a bandaid to be used as a last resort.
it is only available to those who look at source code.
it is useful only for the search engines that support it in their indexing, should they decide to follow it.
it is a hint for search engines and not a directive.
it does absolutely nothing for user agents.
it does nothing to discourage people from linking to the non-canonical url when you serve up a non-canonical url.

canonical: reduced to the simplest and most significant form possible without loss of generality

the "canonical solution" is to provide a 301 redirect to the canonical url, in which case the link element is redundant.

dstiles

11:38 pm on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I did say it was better if it could be fixed in the source. :)

On the other hand, it does seem to help my sites to get garbled URLs homogenized by SEs.

ogletree

11:50 pm on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



With IIS you have to enforce capitalization since IIS will show the same content for upper and lower case URL's. I asked Matt Cutts one time if making sure the whole site used lower case was a good idea and he said yes.

marcel

5:55 am on Dec 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fortunately, there is also a method for this with the rewrite module:

<rule name="Convert to lower case" stopProcessing="false">
<match url=".*[A-Z].*" ignoreCase="false"/>
<conditions>
<!-- The following condition prevents rule from rewriting requests to .axd files -->
<add input="{URL}" negate="true" pattern="\.axd$"/>
</conditions>
<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent"/>
</rule>

blend27

9:49 am on Jan 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



-- how do you solve the default directory index document canonicalization problem without ISAPI_Rewrite? --

One method I used in the past was to rename the default.aspx to anyfilenamewhatever.aspx and set that file/default document as first on the list on Documents Tab in IIS.

Then never link to that file in the code.

No one can link-to/try-to-hack the file if they don't know the name of the file, no matter wHat cASe iT's in, right?

marcel

11:09 am on Jan 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One method I used in the past was to rename the default.aspx to anyfilenamewhatever.aspx and set that file/default document as first on the list on Documents Tab in IIS.

This is also a good option, just make sure that the form action= doesn't point to the filename. You can change that with:

Form1.Action = "/path/to/page/";
* this only works with ASP.net 3.5 SP1