Hello, I've been looking for a few days on UmbracoUrlAlias and UmbracoUrlName. I managed to get both working.
My problem is, if I change all the structure of my website to use the Url Alias instead of Content.Url, will I have problems with SEO? Will my pages show up with the alias or with their primary URL?
I can't use UmbracoUrlName because it only changes the URL in the current structure, and not the structure before it. Example:
mywebsite.com/2015/12/newsarticle
I wanted to be just mywebsite.com/newsarticle (or other name)
I want them to be all shown with the Alias set up by the user, if not, the original URL will be used.
I'm fairly new to Umbraco and SEO, but from what I searched, I believed I'd have to use canonical URL and prioritize the umbraco Url Alias? Can someone confirm me that?
Yes umbracoUrlAlias is an additional alias to the normal Url generated by Umbraco, so your content will be available on
mywebsite.com/2015/12/newsarticle
AND
mywebsite.com/newsarticle
so when the same content is available on different urls, then for SEO the best option is to add a link tag specifying the canonical url that you would like search engines to use regardless of the Url that they discover the content via.
One thing to be aware of is that umbracoUrlAlias is a comma delimited list of alternative urls, (eg you can have more than one alias!! - perhaps assume the first one in the list will always be the canonical one)
So something like this may work for you...
@{
// get the canonical url of the page:
var currentUri = HttpContext.Current.Request.Url;
var port = (currentUri.Port == 80) ? "" : ":" + currentUri.Port;
var siteUrl = currentUri.Scheme + Uri.SchemeDelimiter + currentUri.Host + port;
var canonicalUrl = Model.Content.Url;
// use Umbraco Url alias as the canonical url if it is set
if (Model.Content.HasValue("umbracoUrlAlias"))
{
// umbracourlalias can be a comma delimited string of alterantive urls, the canonical url will be the first
var canonicalUrls = Model.Content.GetPropertyValue<string>("umbracoUrlAlias").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
canonicalUrl = canonicalUrls.FirstOrDefault();
if (!String.IsNullOrEmpty(canonicalUrl))
{
if (!canonicalUrl.StartsWith("/"))
{
canonicalUrl = "/" + canonicalUrl;
}
if (!canonicalUrl.EndsWith("/"))
{
canonicalUrl = canonicalUrl + "/";
}
}
}
canonicalUrl = siteUrl + canonicalUrl;
}
<link rel="canonical" href="@canonicalUrl" />
one thing to be aware of is that Umbraco does not do anything to check that the umbracoUrlAlias the editor is creating, already exists on another node somewhere in Umbraco, so over several years on a site with News around a similar subject it's quite possible for Editors to inadvertently creating clashing urls!!!
I managed to get it working like this, on my master template, inside the head tag:
if (CurrentPage.HasValue("umbracoUrlAlias"))
{
var Alias = CurrentPage.GetPropertyValue("umbracoUrlAlias").ToString();
var UrlCanonical = "http://" + HttpContext.Current.Request.Url.Host + "/" + Alias;
<link rel="canonical" href="@UrlCanonical">
}
Is that okay? I'm not going to use a second Url Alias, so I don't think it will be necessary to split the comma.
I didn't understand why would you check if the string is not starting with a slash, wouldn't this always be true? Because if it starts with a slash, the alias won't work.
Yes as long as your editors aren't aware they can add a list of alias... if they do then your code will error...
I'm messing around with the first / and last / on the example I posted, as that's from an old site, where editors would add both, and it 'used' to work either way!
Relation of UmbracoUrlAlias with SEO?
Hello, I've been looking for a few days on UmbracoUrlAlias and UmbracoUrlName. I managed to get both working.
My problem is, if I change all the structure of my website to use the Url Alias instead of Content.Url, will I have problems with SEO? Will my pages show up with the alias or with their primary URL?
I can't use UmbracoUrlName because it only changes the URL in the current structure, and not the structure before it. Example:
mywebsite.com/2015/12/newsarticle
I wanted to be just mywebsite.com/newsarticle (or other name)
I want them to be all shown with the Alias set up by the user, if not, the original URL will be used.
I'm fairly new to Umbraco and SEO, but from what I searched, I believed I'd have to use canonical URL and prioritize the umbraco Url Alias? Can someone confirm me that?
Thanks
My Umbraco version is 7.5.4
Hi Victor
Yes umbracoUrlAlias is an additional alias to the normal Url generated by Umbraco, so your content will be available on
mywebsite.com/2015/12/newsarticle
AND
mywebsite.com/newsarticle
so when the same content is available on different urls, then for SEO the best option is to add a link tag specifying the canonical url that you would like search engines to use regardless of the Url that they discover the content via.
One thing to be aware of is that umbracoUrlAlias is a comma delimited list of alternative urls, (eg you can have more than one alias!! - perhaps assume the first one in the list will always be the canonical one)
So something like this may work for you...
one thing to be aware of is that Umbraco does not do anything to check that the umbracoUrlAlias the editor is creating, already exists on another node somewhere in Umbraco, so over several years on a site with News around a similar subject it's quite possible for Editors to inadvertently creating clashing urls!!!
eg
mywebsite.com/latest-shipping-news
might occur every month
Thanks for the reply,
I managed to get it working like this, on my master template, inside the head tag:
Is that okay? I'm not going to use a second Url Alias, so I don't think it will be necessary to split the comma.
I didn't understand why would you check if the string is not starting with a slash, wouldn't this always be true? Because if it starts with a slash, the alias won't work.
Hi Victor
Yes as long as your editors aren't aware they can add a list of alias... if they do then your code will error...
I'm messing around with the first / and last / on the example I posted, as that's from an old site, where editors would add both, and it 'used' to work either way!
cheers
Marc
You're right. I just tested, on umbraco, the field can't end with a slash, but it can start with a slash or don't, it works either way. Thanks.
For future references: http://www.codeshare.co.uk/blog/umbracourlalias-create-an-alternative-url-for-a-page-in-umbraco/
is working on a reply...