Site structure
Version 4.x > Site structure > Setting default page in Google Sitemap View modes: 
User avatar
Member
Member
Steve-Appetere - 3/11/2009 7:20:08 AM
   
Setting default page in Google Sitemap
Is there a way to set the default page of the site, so that the Kentico-generated Google Sitemap renders something like:

<loc>http://www.appetere.com/</loc>

rather than:

<loc>http://www.appetere.com/default.aspx</loc>

as now?

This is significant for search-engine optimisation as you often focus on building page-rank for the domain name (http://www.appetere.com/), whereas the search engine will most likely see http://www.appetere.com/default.aspx as a different page, and hence your page rank is diluted.

I can write my own HttpHandler for this, but was just wondering if there was a way to do this with the Kentico version?

Thanks in advance.

User avatar
Member
Member
Steve-Appetere - 3/16/2009 5:38:26 PM
   
RE:Setting default page in Google Sitemap
I've devised a quick solution to the problem, but would still be interested in any more elegant solutions that Kentico CMS provides for this.

My approach was to edit the CMS.Root document type, which contains the GoogleSitemap transformation, which the repeater on /CMSPages/googlesitemap.aspx uses. I then modified the transformation markup as follows:

<url>
<loc><%# System.IO.Path.GetFileName(GetDocumentUrl())=="default.aspx"? GetAbsoluteUrl("/"): GetAbsoluteUrl(GetDocumentUrl())%></loc>
<lastmod><%# GetDateTime("DocumentModifiedWhen", "yyyy-MM-dd") %></lastmod>
</url>

So whenever the default page "default.aspx" is detected, the code will replace it for the Google sitemap with "/", achieving my objective.

User avatar
Member
Member
Steve-Appetere - 3/17/2009 4:06:35 AM
   
RE:Setting default page in Google Sitemap
The inline code could be improved by replacing "default.aspx" with a CMS-maintained variable.

I've found the CMSPageManager.DefaultPageAliasPath property, but this requires an instance of CMSPageManager, which isn't available in the transformation.

Does anyone know if there is a static property containing the same DefaultPageAliasPath I could use here?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 3/17/2009 5:20:11 AM
   
RE:Setting default page in Google Sitemap
Hi,

Your first approach is correct. Also the second seems to be fine, you can try to create custom function for transformation where you can use the CMSPageManager - http://www.kentico.com/docs/devguide/adding_custom_functions_to_tra.htm.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
Steve-Appetere - 3/18/2009 5:09:43 AM
   
RE:Setting default page in Google Sitemap
I tried writing a custom function, but the DefaultPageAliasPath property of CMSPageManager always returns "/" .

In my site:

CMS Site Manager -> Settings -> Default alias path = "default"

But if I run the code below, as a test, I always get "/" returned. Can you spot anything I need to do, to return "default", as expected?


using CMS.Controls;

public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CMSPageManager pageManager = new CMSPageManager();
Response.Write(pageManager.DefaultPageAliasPath);
}
}


Thanks,

Steve

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 3/19/2009 9:21:48 AM
   
RE:Setting default page in Google Sitemap
Hi,

I am sorry for the confusion. I understood you wrong before.

Anyway, you will need to create custom function where you will check the absolute URL, and if it will be http://www.domain.com/ you will add to it the "default.aspx".

Moreover, the setting for the default alias path means which document should be displayed as the default. So for example you can set there "/News" and when you will access your site using www.domain.com or www.domain.com/default.aspx, the News document will be displayed.

Best Regards,
Juraj Ondrus

User avatar
Member
Member
Steve-Appetere - 3/19/2009 9:41:30 AM
   
RE:Setting default page in Google Sitemap
Thanks for the reply, but what I want to do is actually the other way round:-

So my custom function must look for:

http://www.appetere.com/default.aspx

and replace it with:

http://www.appetere.com/

BUT to generalise the function, I don't want to hard-code the text "default.aspx".

So I was trying to find a Kentico CMS property that would contain the default alias path defined in Site Manager (which in my case would be "/default").

I tried using CMSPageManager.DefaultPageAliasPath BUT the value of this property is always "/" rather than the default alias path (as described in my previous post).

So this leaves two questions:

1. Is CMSPageManager.DefaultPageAliasPath meant to always be "/"?

2. If question 1. = yes, then if there another Kentico CMS property I can use that will contain the default alias path set in Site Manager?


User avatar
Kentico Developer
Kentico Developer
kentico_martind - 3/20/2009 8:48:31 AM
   
RE:Setting default page in Google Sitemap
Hello,

You can use sample code bellow to get value of specified key from settings:

CMS.SettingsProvider.SettingsKeyProvider.GetValue("CMSDefaultAliasPath"); //global setting

CMS.SettingsProvider.SettingsKeyProvider.GetValue("SiteName.CMSDefaultAliasPath"); //site setting

You can find names of other keys in CMS_SettingsKey table in DB.

Best Regards,

Martin Dobsicek

User avatar
Member
Member
Steve-Appetere - 3/20/2009 10:54:27 AM
   
RE:Setting default page in Google Sitemap
Ahh .. easy once you know where to look..! Thanks.

Thought an example of the finished solution might be useful for others (below). Why this is important to do if you want to build page rank with Google is outlined earlier in the thread!

First, in:

Document Types -> CMS.Root -> Transformations -> GoogleSiteMap

modify the transformation, similar to the following:

<url>
<loc><%# Appetere.GoogleSitemapUtils.GetUrlForSitemap( GetDocumentUrl() )%></loc>
<lastmod><%# GetDateTime("DocumentModifiedWhen", "yyyy-MM-dd") %></lastmod>
</url>

Then add a class file to the App_Code directory (or sub-directory), which contains the static method the transformation uses:


// your usual "using" statements plus:

using System.IO;
using CMS.Controls;
using CMS.GlobalHelper;
using CMS.CMSHelper;

namespace Appetere
{
/// <summary>
/// Utility class to help generate Google Site Map
/// </summary>
public static class GoogleSitemapUtils
{
private static readonly string _defaultAlias = string.Empty;
private static readonly string _siteName = string.Empty;

static GoogleSitemapUtils()
{
CMSPageManager pageManager = new CMSPageManager();
_siteName = pageManager.SiteName;

_defaultAlias = CMS.SettingsProvider.SettingsKeyProvider.GetValue(_siteName+".CMSDefaultAliasPath");

}
/// <summary>
/// Returns the same URL received, unless is the default page for the site
/// when replaces filename with "/"
/// </summary>
/// <param name="documentUrl">URL to check</param>
public static string GetUrlForSitemap(string documentUrl)
{
if (documentUrl==null)
{
throw new Exception("documentUrl parameter was null when generating Google sitemap");
}

if (Path.GetFileNameWithoutExtension(documentUrl) ==
Path.GetFileNameWithoutExtension(_defaultAlias))
{
return UrlHelper.GetAbsoluteUrl("/");
}
else
{
return UrlHelper.GetAbsoluteUrl(documentUrl);
}
}
}
}


Then if you check out /CMSPages/GoogleSiteMap.aspx for your domain, the default page will now be shown as "/", hopefully rewarding you with a tiny bit more Google page rank for your efforts.