URL rewriting in Blog Engine.NET

by Prashant 5. June 2010 23:47

I was just looking for a way to get short URL’s for my blog, I used some extensions, some URLrewriter.NET but still not able to get this work. So I drop an e-mail to Scott Hanselman and was waiting for his response. If you look at Scott’s blog you will see that he has very simple URL for his blog posts which eventually get his posts higher ranks on search engine indexing. What I have found so far is that if you have a simple URL the search engine will crawl that page during indexing and your page is on the top of the search results or if it is not on the top then it must be at least on the first page. Remember search engine crawlers will avoid crawling pages that do not have a simple URL, like if your page has a query string it won’t be get crawled by the search engine crawler.

The URLRewriter module in BlogEngine didn’t seems to be working for Posts. I want to have simple SEO friendly URLs like http://www.midnightprogrammer.net/post/Windows-7-Logon-Screen-Changer.aspx and not http://www.midnightprogrammer.net/post/2010/05/30/Windows-7-Logon-Screen-Changer.aspx But there is no way to do this until I hook into BlogEngine.Core.dll.

Open the whole solution in Visual Studio and open Post.cs file and navigate to the RelativeLink property in Post.cs file and change with the below code:

public string RelativeLink
{
	get
	{
		string slug = Utils.RemoveIllegalCharacters(Slug) + BlogSettings.Instance.FileExtension;
		if (BlogSettings.Instance.TimeStampPostLinks)
			return Utils.RelativeWebRoot + "post/" + slug;
		return Utils.RelativeWebRoot + "post/" + slug;
	}
}

Recompile your DLL and place in bin directory in your blogengine root folder. Now you will have short URLs which do not have any date stamp. Having short URLs for all your posts doesn’t affect the posts with old URLs that most of the people have bookmarked on their blogs or on social bookmarking sites. Hope this helps.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags:

BlogEngine.NET


Comments (4) -

Rahul kant
Rahul kant United States
8/6/2010 8:34:11 AM #

Nice information.  thanks

Reply

Cristian
Cristian Italy
11/5/2011 5:03:58 AM #

canging this

http://localhost:52457/BlogEngine.NET/default.aspx

in this ?
http://localhost:52457/default.aspx
thanks

Reply

Nabil
Nabil Canada
12/3/2011 8:13:08 AM #

I couldn't find the code you're referring to. Maybe they change it in the latest version? could you please help?

Thanks,
Nabil

Reply

Prashant
Prashant India
12/3/2011 9:05:21 PM #

@Nabil: Which version of BE you are using? I have this post when I was using 1.5.0 and the code was intact in BE 2.0 also. If you are using BE 2.0 then you will be able to find the above code.

Reply

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Visit blogadda.com to discover Indian blogs Computers Blogs

About Me

Name of authorPrashant Khandelwal.
Programmer and tech enthusiast. More...

Feeds Subscribe Twitter Facebook Google Plus Linked In Delicious

Badges

MVB

MVP Blog Badge.

HTML5 Powered with CSS3 / Styling, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage

Month List

Blog Stats

414,286 Hits

Adverts

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012

Creative Commons License