Can you change the friendly url pattern?

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.
9/28/2011 4:56:46 AM
Gravatar
Total Posts 137
When enough isn't

Can you change the friendly url pattern?

Hi,

I finally found out how to use the suggestfriendlyurl feature of MojoPortal in my code on some custom modules. In that way I can add to the friendly url table to make it possible to work with queryparameters in the background and show friendly urls to the users. Nice! .. very much inspired by the article http://www.mojoportal.com/using-friendly-urls-in-custom-features.aspx and studying the blogedit code.

But in my country we have three very special characters that I want to avoid in my suggested urls. Are there anyway I can change the default friendly url pattern to cope directly with those characters so that e.g. "æ" gets substituted with "ae" and "ø" to "o"?

My plan B would be to write some code that finds these characters in the suggested friendly url, then substitue manually and then run an additional suggested friendly url request before saving to the table. Or what ever i can come up with.

Best regards
Lars

Denmark
 

9/28/2011 7:28:39 AM
Gravatar
Total Posts 18439

Re: Can you change the friendly url pattern?

Hi Lars,

We have a method that will try to convert characters such as those to their closes ascii equivalent. I don't know if it works perfectly but you can try adding this to your user.config file and try it out:

<add key="UseClosestAsciiCharsForUrls" value="true"/>

then it should suggest new urls with those characters replaced, it won't affect existing urls.

Hope that helps,

Joe

9/28/2011 12:34:31 PM
Gravatar
Total Posts 137
When enough isn't

Re: Can you change the friendly url pattern?

Hi,

Thanks for the suggestion. I tested it and this is what happens to the three characters:

"æ" is replaced by nothing. Best if "ae".

"ø" is replaced by nothing. Best if "o".

"å" is replaced by "a". Best if "aa".

So if you want to do a quick and dirty to avoid "%"-characters in your urls it does work. But if you want to create readable urls it doesn't. So I guess that will be individually.

In my case I will try to make code following my plan B. Thanks anyway and I will feed back here what it leads to.

Best regards

Lars

 

 

 

9/28/2011 6:28:57 PM
Gravatar
Total Posts 137
When enough isn't

Re: Can you change the friendly url pattern?

Hi again,

I just want to feed back on my further coding. The code below works ... it transformes this test-text:

From: "Titel a b c æ ø å Å Ø Æ 123 æøåÆØÅ"

 To: "titel-a-b-c-ae-o-aa-aa-o-ae-123-aeoaaaeoaa.aspx"

In the code you just define a number of characters or even words separated by ";". You define a string with the original characters and another string with new characters to substitute with. The code consist of two parts. One to define the special characters and to suggest the friendly url plus another more general part to substitute text.

Here it is (sorry for some danish words):

// Finds a friendly url for a certain text including substitution of danish special characters
public string FriendlyUrl(string tekst)
{
    string friendlytekst;
   
    string origtegn = "æ;ø;å;";
    string nytegn = "ae;o;aa;";

    tekst = UdskiftTegn(tekst.ToLower(), origtegn, nytegn);
    friendlytekst = SiteUtils.SuggestFriendlyUrl(tekst, siteSettings);
   
    return friendlytekst; 
}

// Substitutes original characters with new characters defined in otegn and ntegn
public string UdskiftTegn(string tekst, string otegn, string ntegn)
{
    string nytekst = tekst;
    string oakt;
    string nakt;
    int tegnpos = otegn.IndexOf(";");
   
    while (tegnpos >= 0)
    {
        oakt = otegn.Substring(0, tegnpos);
        otegn = otegn.Substring(oakt.Length + 1);

        tegnpos = ntegn.IndexOf(";");
        nakt = ntegn.Substring(0, tegnpos);
        ntegn = ntegn.Substring(nakt.Length + 1);

        tegnpos = nytekst.IndexOf(oakt);
        while (tegnpos >= 0)
        {
            nytekst = nytekst.Substring(0, tegnpos) + nakt + nytekst.Substring(tegnpos + oakt.Length, nytekst.Length - tegnpos - oakt.Length);
            tegnpos = nytekst.IndexOf(oakt);
        };

        tegnpos = otegn.IndexOf(";");
    };

    return nytekst;
}

As you can see this can also be used more generally to do substitutions like from "adventurerace;alcohol;æ;ø;å;mojoportal;" to "AR;water;ae;o;aa;mojo;" wink.

Best regards
Lars
 

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