Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • trfletch 598 posts 604 karma points
    Mar 11, 2010 @ 13:51
    trfletch
    0

    URL rewriting for SEO purposes

    Hi, I have an Umbraco V4 website and I would like to make the URL's search engine optimised. The site is a vacancy website and will have pages as follows:

    Jobs
         - Job 1
         - Job 2
         - Job 3

    These pages have got a property that is called Location and what I would like to be able to do is have the URL something like this:

    www.mywebsite.com/job-1-in-London.aspx

    How can I achieve this without the user having to call the node "job 1 in london" or without having to use umbracoUrlName? Basically I want the SEO url to be created automatically without the end user having to do anything (I would probably want to add the node ID to the URL or some other unique number so that I don't get any duplicate URLs). Is this possible using XSLT or is it possible at all for that matter?

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 11, 2010 @ 14:34
    Dirk De Grave
    0

    I don't see why you don't want to use the umbracoUrlName property that's being populated based on the document properties. How else would you handle this? Create your own property and set the url name to whatever needs to be there (using event handlers that'll spit out that url)?

    I'd still use the umbracoUrlName property and populate that with your own generated seo url

     

    Cheers,

    /Dirk

  • trfletch 598 posts 604 karma points
    Mar 11, 2010 @ 14:43
    trfletch
    0

    Hi Dirk,

    When you say populate it with document properties what do you mean? Do you mean it is possible to have it populated automatically with for example the nodeName, the value of the Location property and the node ID? If it is then this is perfect and exactly what I want to do. I just don't want the Umbraco user to have to enter something in there manually because they are likely to forget or likely to enter duplicate information (which I assume will cause a problem?).

     

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 11, 2010 @ 16:08
    Dirk De Grave
    0

    By populating I mean: subscribe to the document save/publish event and set the property of the umbracoUrlName to your custom generated url based on the documents properties.

    An introduction to event handling in umbraco can be found in the wiki section.

    And now that I've got your attention, be aware about the difference between umbracoUrlName and umbracoUrlAlias

     

    Let us know if you need some examples.

     

    Cheers,

    /Dirk

     

  • trfletch 598 posts 604 karma points
    Mar 11, 2010 @ 16:26
    trfletch
    0

    Hi Dirk,

    Yes some examples would be nice if you don't mind, is it also possible using this to change the nodeName when saved so that it has a unique number on the end (possibly the node ID).

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 11, 2010 @ 17:10
    Dirk De Grave
    0

    not sure if changing the node name is a great idea, and especially if you're going to use umbracoUrlName property on the content document as this property changes the url when it's saved to cache and therefore when is requested using NiceUrl()

    you can change the nodeName by using the .Text property on the document.

     

    public class AppBase : umbraco.BusinessLogic.ApplicationBase {

       
    public AppBase() {
           
    Document.BeforeSave += new Document.PublishEventHandler(Document_ BeforeSave );
        }

       
    void Document_B BeforeSave (Document sender, PublishEventArgs e) {
    sender.Text = sender.Text + sender.getProperty("LocationAlias").Value.ToString() + " (" + sender.Id.ToString() + ")";   
        }
    }

     

    (just an example and untested!)

     

    Cheers,

    /Dirk

  • trfletch 598 posts 604 karma points
    Mar 11, 2010 @ 17:20
    trfletch
    0

    Thanks Dirk,

    Just been reading up and I think I'm starting to understand how to use the Event Handlers. Can you give me an example of how I would change the url to be: nodename-in-location-nodeID.aspx

    Do I need to add the  umbracoUrlName as a property for the document? Also how do I restrict it so that it only changes the URL's for a certain document type. I dont want normal pages having their url changed especially as they will not even have the location property!

  • jonok 297 posts 658 karma points
    Mar 11, 2010 @ 21:50
    jonok
    0

    Hi, you can check the document type alias with the following code so that you only execute your changes on certain document types:

           if (sender.ContentType.Alias == "YourDocTypeAlias")

     

  • jonok 297 posts 658 karma points
    Mar 11, 2010 @ 22:02
    jonok
    0

    And yes, you need to add the umbracoUrlName as a property and then you can modify it like this with the node ID on the end to keep it unique:

                if (sender.ContentType.Alias == "YourDocTypeAlias")
                {

                    sender.getProperty("umbracoUrlName").Value = sender.Text + "-in-" + sender.getProperty("Location").Value.ToString() + "-" + sender.Id.ToString();
                   
                }
Please Sign in or register to post replies

Write your reply to:

Draft