In the UrlRewrite module, the RewritePost() method is not matching the date in a post's url correctly to the date of a post. Here are the conditions:
- Two blog posts have the same slug.
- The blog posts are posted on different days.
- The 'Add date to post links' option is selected.
If you try to access the older post, BE currently retrieves the newer post (this is incorrect). The relevant code in RewritePost() looks like:
if (date != DateTime.MinValue && (p.DateCreated.Year != date.Year || p.DateCreated.Month != date.Month))
if (p.DateCreated.Day != 1 && p.DateCreated.Day != date.Day)
I don't understand what the "p.DateCreated.Day != 1" part is for, but the code below works correctly. Note, I omitted the "p.DateCreated.Day != 1" part just because it doesn't seem necessary.
if (date != DateTime.MinValue &&
(p.DateCreated.Year != date.Year ||
p.DateCreated.Month != date.Month ||
p.DateCreated.Day != date.Day))
This fixes the problem described above.
There's still a separate, but related problem however, if the 'Add date to post links' option is not selected. In this case, if you try to access the older post, BE still retrieves the newer post. Even if you try to get to the older post via the Permalink,
BE still shows the newer post. The reason for this is because when a post is retrieved by guid, in post.aspx.cs, a 301 redirect is done with the new location being the RelativeLink. When this is done, the RewritePost() method in UrlRewrite can't distinguish
between the older post and the newer post based on the RelativeLink when there's no date in the url.