A few days ago I subconsciously made the decision to remove dates from post URL on my site developed on BlogEngine.net platform, an open source CMS in Asp.net.
The functionality available on Settings in the section Other Settings, allows you to add or remove dates from post URLs simply by checking or unchecking the item Add the date to the Post link.
Unfortunately for me this removal operation has had a negative impact and serious SEO side damage to SoulTricks.
How to remove the date from the post URL
While WordPress manages the deletion of the date from the URL of the posts with different plugins, BlogEngine does not provide an ad hoc function that helps the user to solve this problem, and this creates a certain annoyance for search engines like Google, which interpret the your articles as duplicate articles, even if you have provided a valid sitemap and with new URLs. In this regard, take a look in Search Google in the section Appearance in Search> HTML Enhancement> Duplicate Meta Tag Title, to show that the duplicate posts are precisely those with date and without date. For example something like this:
How to type on your PC keyboard without looking
/post/2016/05/14/come-scrivere-sulla-tastiera-del-pc-senza-guardare.aspx
/ post / 2016/05/14 / how-to-write-on-the-pc-keyboard-without-looking
This situation has caused a loss of positioning of my articles in search engines and an evident drop in daily visits. In the meantime, I tried to search the Internet for the solution to this problem how to remove dates from post URL in Asp.net or C # and how to do a permanent 301 redirect. But nothing at all. Therefore?
Here is how I solved in BlogEngine.net:
- Downloaded the latest version of Visual Studio in the free version
- Downloaded the BlogEngine.net (source) file of the version you are using.
- Opened the BlogEngine.sln version in Source / Blogengine
- In Visual Studio Solution Explorer open BlogEngine.Core> Web> UrlRules.cs
In this file I have added the following lines of code:
In the #region Constants and Fields of the UrlRules class
private static readonly Regex YearMonthDayRegexs = new Regex("/([0-9][0-9][0-9][0-9])/([0-1][0-9])/([0-3][0-9])/", RegexOptions.IgnoreCase | RegexOptions.Compiled);
In the method ExtractTitle, which receives as a second parameter the url of the posts, you have to write the following lines of code inside immediately after this line of code
url = url.ToLowerInvariant().Replace(“—“, “-“);
if (url.Contains("/post/") || url.Contains("/POST/")) { if (YearMonthDayRegexs.IsMatch(url)) { var match = YearMonthDayRegexs.Match(url); var year = match.Groups[1].Value; var month = match.Groups[2].Value; var day = match.Groups[3].Value; url = url.ToLowerInvariant().Replace("/" + year.ToString(), ""); url = url.ToLowerInvariant().Replace("/" + month.ToString(), ""); url = url.ToLowerInvariant().Replace("/" + day.ToString(), ""); if (url.Contains("?")) { url = url.Substring(0, url.Length - 1); } context.Response.AppendHeader("location", url); context.Response.StatusCode = 301; } }
However, if your posts have a URL ending with the .aspx extension, you will need to move these lines of code right after this statement:
if (url.Contains(BlogConfig.FileExtension) && url.EndsWith("/")) { url = url.Substring(0, url.Length - 1); context.Response.AppendHeader("location", url); context.Response.StatusCode = 301; }
This way your old articles containing the date in the URL will be redirected to an undated URL, just like in the example below:
- da: /post/2013/10/11/come-trasferire-i-contatti-e-altri-dati-da-iphone-ad-android.aspx
- to: / post / how-to-transfer-contacts-and-other-data-from-iphone-to-android
When finished in Visual Studio, go to the menu Compilation and select Ricompila BlogEngine.Core. Wait for the operation to complete, then go to SourceBlogEngineBlogEngine.CorebinRelease to copy the file Blogengine.core.dll and paste it into the folder bin in the root of your site. And that's it!
If you don't want to get involved with the BlogEngine.Core, you can try to intervene in the Web.Config with these lines of code. Attention is to be tested since I have not tried it.
Having said that, I have to make a special thanks to two great bloggers who, with their availability, helped me to get out of this bad situation, and whom I really admire and respect:
Luca Congiu: asp.net developer and DotNetCode.com blogger and author of some articles on SoulTricks.com
Giorgio Borelli: author and creator of the blog Informaticando.net - a web around information technology.