This project is read-only.

Url re-writing in post content

Topics: ASP.NET 2.0
Dec 7, 2010 at 11:11 AM

Hi.I am new to BlogEngine and have migrated my site from Wordpress to ver 1.6.1 of BlogEngine. This has mostly gone well but there is one problem I can't seem to solve.

If I create a post e.g. "My new test post 1"  which contains a link to another post e.g. <a href="post/My-new-test-post-2.aspx">link to test post 2</a>

 or a link to another page e.g. <a href="page/My-new-test-page-1.aspx">link to test page 1</a>

the links remains unchanged when viewed from <uc1:PostList... in default.aspx.

However if I navigate to the post containing the links and then view the links they have appear as follows:




Neither of these links works.

Can anyone tell me where these are being changed in this way?



Dec 8, 2010 at 1:10 AM

Try changing the URLs in your hyperlinks so they begin with a leading forward slash.  So instead of:


.... change that to:


Without the leading forward slash, the link is only valid while on the homepage (in the root folder).  Once you are viewing the post individually, that link you have will no longer point to the right location and will end up incorrectly navigating to /post/page ... like you are seeing.

Dec 8, 2010 at 11:26 AM

Thanks for your reply. When I add the leading forward slash as you suggest, the link displays on hover in the status bar as http://localhost/post/My-new-test-post-2.aspx. When i click on the link I get the following error:

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. Requested URL: /post/My-new-test-post-2.aspx

When I open the post containing the link and hover over the link, this time it displays as http://localhost/post/My-new-test-post-2.aspx, but I get the same error when I click on the link.
In other words the link fails because the relative web root (GFF.Web) is missing

If I stick ANY string in front of the "/post" string e.g. "zzz" the link on hover displays as  http://localhost/GFF.Web/zzz/post/My-new-test-post-2.aspx. This works.

When I open the post containing the link and hover over the link, this time it displays as http://localhost/GFF.Web/post/zzz/post/My-new-test-post-2.aspx. This also works.

If I do the same with the /page type link, it displays in uc1:PostList with the zzz string and works.

When I open the post and hover it displays as http://localhost/GFF.Web/post/zzz/page/My-new-test-page-1.aspx. When i click on the link it fails with "Server Error in '/GFF.Web' Application".
Requested URL: /GFF.Web/post/zzz/page/John-Martyn-studio-albums.aspx.

Not an entirely successful experiment. Is anyone managing to successfully place relative links in their blog posts? If so can they please tell me where I am going wrong?

Dec 8, 2010 at 10:46 PM

If you're on localhost where the blog is in a sub-application, then the simple answer is that when creating posts on localhost, the URL you specify should be: /GFF.web/post/....   And if your blog is hosted in the website root, then you should use a URL like /post/...

BE isn't doing any URL rewriting for these links.  They are output as-is in your pages & posts.  Because a post is shown at different folder levels, it is necessary to prefix the URL with a forward slash (or use an absolute URL).  The 2 main folder levels a post is shown at is while on the homepage where the folder level is /  ... and the 2nd folder level is when an individual post is shown and the folder level is /post/ (one level deep), or if you have dates in your post URLs, the folder level will be /post/2010/12/08/... (4 levels deep).

Having said this, a BE extension could be created that looks at the URLs in your links, and changes them based on the current location (the current folder level).  But for getting things to work, the simple solution is to prefix the URLs with the appropriate prefix, based on the location of your blog (localhost/GFF.web, or a site root).