How to avoid Canonical urls on specific pages?

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
5/31/2010 1:51:52 AM
Gravatar
Total Posts 137
When enough isn't

How to avoid Canonical urls on specific pages?

Hi

We have some pages, e.g. "/loeb.aspx", where we use query strings for a range of diffent page contents (dynamical pages) taken from our database. That means that http://www.boostadventure.dk/loeb.aspx?id=500 is very different from http://www.boostadventure.dk/loeb.aspx?id=130.

BUT in the sourcecode I can see that MojoPortal automaitcally forces a conical url to "/loeb.aspx", which means that we totally confuse google and none of these pages gets indexed.

How can we avoid/override those canonical urls on certain pages with some settings and/or C# code?

(I fully understand why canonical urls are used in MojoPortal as all search engines adapted to that last year. But this seems to be the flipside of the problem solved).

Any help or suggestions?

Best regards

Lars, Denmark

5/31/2010 6:12:56 AM
Gravatar
Total Posts 18444

Re: How to avoid Canonical urls on specific pages?

Hi Lars,

In a custom feature I recommend don't do the paging in the module control on the CMS page itself, link to a supporting page where the paging will happen so that they will have unique urls for each page and in your custom supporting page you can either leave out a canonical url or add your own according to your own logic.

Look at the blog on this site for example at the bottom is a pager, but as soon as you click a pager link you are no longer on the cms page blog.aspx but on a supporting page. You must also pass the pageid and mid (moduleid) to your supporting page along with your custom param.

Module controls that live on a CMS page (ie a virtual page in the menu) should not use extra query string params because it should be able to live on a page with other modules and no module should interfere with another.

Hope it helps,

Joe

5/31/2010 7:36:59 AM
Gravatar
Total Posts 137
When enough isn't

Re: How to avoid Canonical urls on specific pages?

Hi Joe - thanks for a quick answer as always.

I think I get your idea about separating modules from pages. But in order to experiment I need a few more details. Those are my questions right now:

- Where exactly is the canonical url set (in code behind default.aspx, in code behind all pages including a custom page)?

- What is the purpose of passing the pageid and moduleid's - is that to be able to return to the page?

- If I want my url to look short, e.g. "loeb.aspx?id=500", could I rather then pass the pageid and moduleid values in session parameters?

- Just to be clear: Then on the custome page I should make a script that sets canonical url to "custom.aspx?id=500" so that if this page was called from another module and another page it would still count as only the one and same url for the search engines?

Sorry about all those questions, but I'm still on a learning curve .. wink.

Best regards Lars

5/31/2010 9:12:30 AM
Gravatar
Total Posts 18444

Re: How to avoid Canonical urls on specific pages?

Hi Lars,

For pages in the menu aka CMS pages, yes, canonical url is set in code behind of Default.aspx.cs like this:

if ((Page.Header != null)&& (CurrentPage.UseUrl) && (CurrentPage.Url.Length > 0))
            {
                string urlToUse = SiteRoot + CurrentPage.Url.Replace("~/", "/");
                if (CurrentPage.CanonicalOverride.Length > 0)
                {
                    urlToUse = CurrentPage.CanonicalOverride;
                }
                Literal link = new Literal();
                link.ID = "pageurl";
                link.Text = "\n<link rel='canonical' href='"
                    + urlToUse
                    + "' />";

                Page.Header.Controls.Add(link);

            }

for supporting pages it is up to each developer to add canonical url using their own code, so yes you would need to add your own logic similar to above in your custom code.

The purpose of passing the pageid and module id is both to keep the menu highlighted for the current page, to be able to link back to the current page, and to be able to enforce page and module view/edit permissions in your supporting page. There are helper methods in mojoBasePage you can call to check permissions with the module and page id

if you maintain pageid and moduleid some other way it still will not highlight the menu correctly if pageid is no in the url. When you are on a cms page with a friendly url, the friendly url is already really mapping to a real url /Default.aspx?pageid=x but you don't see this because of url re-writing. But once you navigate to a non cms page the pageid must be passed in order to have the menu highlighted and also to have a CurrentPage object that is correct. Also if search engines don't have the pageid or moduleid in the url then if a user clicks the search result there will be nothing already in sessions so there will be no way to determine the page or module. 

The other alternative is to implement friendly urls in your custom feature that link to a detail page, similar to what we have in the blog or webstore. For example in WebStore we have links to product detail page using friendly urls like /productname.aspx, but it maps to a real url /WebStore/ProductDetail.aspx?pageid=x&mid=y&product=z but because we use friendly urls with url rewriting the user does not see the paramters they see the friendly url /productname.aspx

You could study existing features like blog and webstore to learn how to implement friendly urls in your own feature. Friendly urls are even better for SEO because they can have key words in them as compared to some number identifier in a parameter. So if I have a product url like /panasonic-bluray-dvd-player.aspx that will be a better url than /productdetail.aspx?item=x in terms of SEO because the url indicates and re-enforces what the content on the page is.

Hope it helps,

Joe

5/31/2010 9:24:44 AM
Gravatar
Total Posts 137
When enough isn't

Re: How to avoid Canonical urls on specific pages?

Thanks a lot - I'll go ahead based on this very good explanation.

The rewrite url part sounds very interesting. I thought that was a closed area within MojoPortal, that I couldn't touch. Is there a function/method or something I can call to rewrite and read the urls. I can see the table in my MySql database where the translation is stored, mp-FriendlyUrls, but that seem to require that you handle three GUIDs.

Anyway I will explore the customer page part and revert. Thanks for now smiley.

Best regards, Lars

5/31/2010 9:35:29 AM
Gravatar
Total Posts 18444

Re: How to avoid Canonical urls on specific pages?

You don't have to touch the re-writer, you can use the FriendlyUrl class to create friendly urls that map to real urls and to check for existing urls or suggest friendly urls from text strings like blog post titles or product names. But on your custom object then you must also store the friendly url internal to your object so that when you retireve a list of the objects you can link to the friendly urls. Once the friendly url record is created in the db by the FriendlyUrl class, then the url re-writer will see any request for the friendly url and will re-write it to the real url.

It will become clearer if you study the save methods in WebStore/AdminProductEdit.aspx.cs or in mojoPortal.Features.UI/Blog/EditPost.aspx.cs, you will see the code where we create friendly urls and you will see we also save the friendly url on the product object and on the blog object for use in creating internal links to the friendly urls.

If you delete one of your object items then you should also delete the url. If your custom object has a guid identifier, you should set the PageGuid on the FriendlyUrl to that guid so that if you want to delete the url you candelete it by the PageGuid assigned to the friendly url. So for blog urls we use BlogItemGuid for the FriendlyUrl.PageGuid and for Products we use ProductGuid, and for cms pages we use PageGuid of the cms page, so when we delete a page we also make sure to delete the friendly urls by page guid.

If you do use friendly urls then you would want to use the friendly url also in the canonical url.

Hope that helps,

Joe

5/31/2010 3:47:57 PM
Gravatar
Total Posts 137
When enough isn't

Re: How to avoid Canonical urls on specific pages?

Thanks a lot.

That helped. Now I have created a single custom page that can handle 1000 different pages from my database and with no canonical url statement. That's huge for me.

I have a few less important questions to the custom page. I have used the code from this link: http://www.mojoportal.com/usinginlinecode.aspx

  • If I use Artisteer how can I then transfer the full styling to the custom page? My master file seem to transfers a lot to the custom page, but e.g. right column is missing and I can't put anything into the "rightContent" panel
  • To make the custom page work I had to erase two lines of code (this.allowSkinOverride = true PLUS this.SuppressPageMenu() ). Should I be ok with that?
  • It seems as I can't put a module into my custom page using the <portal:ModuleWrapper ID="something" runat="server" ConfigureModuleID="number" />. Is that true?

Thanks again ... and I will continue to finalize the details and (perhaps) take on the challenge to follow your advices about url rewriting.

Best regards, Lars


6/1/2010 7:21:50 AM
Gravatar
Total Posts 18444

Re: How to avoid Canonical urls on specific pages?

Hi Lars,

Assuming your page is using mojoBasePage and our master page from your skin, inside your .aspx your skeleton code should be like this to support Artisteer:

<asp:Content ContentPlaceHolderID="leftContent" ID="MPLeftPane" runat="server" />
<asp:Content ContentPlaceHolderID="mainContent" ID="MPContent" runat="server">
<portal:mojoPanel ID="mp1" runat="server" ArtisteerCssClass="art-Post" RenderArtisteerBlockContentDivs="true">
<mp:CornerRounderTop id="ctop1" runat="server" />
<asp:Panel id="pnl1" runat="server" CssClass="panelwrapper ">
<h2 class="moduletitle">Your Title</h2>
    <portal:mojoPanel ID="MojoPanel1" runat="server" ArtisteerCssClass="art-PostContent">
<div class="modulecontent">

Your custom markup goes here.

</div>
</portal:mojoPanel>
 <div class="cleared"></div>
</asp:Panel>
<mp:CornerRounderBottom id="cbottom1" runat="server" />
</portal:mojoPanel>
</asp:Content>
<asp:Content ContentPlaceHolderID="rightContent" ID="MPRightPane" runat="server" />
<asp:Content ContentPlaceHolderID="pageEditContent" ID="MPPageEdit" runat="server" /> 

If you want to show side panel content in your supporting page call this method on the base page:

LoadSideContent(true, true);

It is ok to remove the SuppressPageMenu();

If you remove the this.allowSkinOverride = true; then your page will not support page level skins or user skins it will only use the site default skin.

You should not include your module or any other using ModuleWrapper in my opinion, this page is for supporting your module not hosting your module, you should put whatever  code you need there to support your feature.

Hope it helps,

Joe

6/1/2010 8:19:15 AM
Gravatar
Total Posts 137
When enough isn't

Re: How to avoid Canonical urls on specific pages?

Thanks

I can't make it all work, but I'm absolutely ok for now. I understand the importance of doing alle the code ON the custom page and not try to contain modules. That's fine, as the basic layout and menus seem to work from the master.

Best regards, Lars

You must sign in to post in the forums. This thread is closed to new posts.