Questionable URL

Topics: ASP.NET 2.0
Oct 24, 2010 at 9:36 PM
Edited Oct 24, 2010 at 9:36 PM

Hello,

Is it possible to make a change to the blog post URL from http://www.example.com/post/example-blog-post-slug.aspx to http://www.example.com/example-blog-post-slug.aspx. From there, would it be possible to remove the ASPX extension altogether (for blog posts only though, e.g. it would still be required for actual pages [default.aspx, contact.aspx, archive.aspx])?

I have experimented within UrlRewrite.cs and in particular, this piece... [Lines 64 - 67]

if (url.Contains("/POST/"))
{
	RewritePost(context, url);
}

I found out that if I removed '/POST/' and recompiled, the individual blog post could be viewed from: http://www.example.com/example-blog-post-slug.aspx - in that example. One 'side affect' to this method was, not all the category links worked; one of the three categories returned an error - two of the three links worked fine, displaying the list of posts from said category, whilst one link returned the generic 'Ooops! I can't find the page you're looking for' error.

I would appreciate some help with rewriting the BLOG POST URL to the example: http://www.example.com/example-blog-post-slug.aspx

Thanks,

Coordinator
Oct 24, 2010 at 11:18 PM

If you're going to remove /POST/ like you did, I would move that code so it is the last past of that large IF - ELSE IF block of code.  So the last ELSE IF checks for /BLOG.ASPX.  So you would want to move that piece of you code you modified (that calls RewritePost()) so it is after BLOG.ASPX.  It would look like:

else if (path.Contains("/BLOG.ASPX"))
{
	context.RewritePath(Utils.RelativeWebRoot + "default.aspx?blog=true" + GetQueryString(context));
}
else
{
	RewritePost(context, url);
}
I think there's maybe more to it than just this, but this should at least help with making the category links work again.