MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Blog posts needing / at their end else get 404  (Mono Support )

Viewed 7302 time(s), 5 post(s) 3/20/2017 6:20:07 PMby Zoomicon


3/20/2017 6:20:07 PM
I was notified that url
was not working while this was working OK:
worse is that Edge browser hides the trailing / after you visit the url (and shows it again if you click on the address bar), so user can be tricked when copy-pasting the url thinking they can safely remove the trailing / - which is what most people would expect btw to be able to do)

to fix it temporarily I spotted in web.config this rule:

     <rewrite url="^(.*)/(.*)/post/(.*)/(.*)/(.*)/(\?(.+))?$" to="$1/$2.aspx?BlogSlug=$3&amp;BlogPostId=$4&amp;$7" name="BlogPost" defaultPage="/Blog.aspx" urlPattern="/{PageName}/post/{Blog.Slug}/{IdentityId}/{Slug}/" />       

and added after it this one:

<!-- fix (trafilm): blog post urls needed / to be at the end to work -->
        <rewrite url="^(.*)/(.*)/post/(.*)/(.*)/(.*)(/(\?(.+))?)?$" to="$1/$2.aspx?BlogSlug=$3&amp;BlogPostId=$4&amp;$7" name="BlogPost" defaultPage="/Blog.aspx" urlPattern="/{PageName}/post/{Blog.Slug}/{IdentityId}/{Slug}/" />

I wonder though why the 2nd rule I added doesn't work with / at the end. That is I need to keep your previous rule too for urls without / and with / at the end to both work. Could I somehow merge these two rules?

also I wonder if this is the correct way to fix it or if I could somehow append the / with a rule where missing and then let the existing rule handle it.
moreover I'm worried if one visits the page without the / at the end, if they use edit action etc. if something will be broken in that aspect (haven't tried the fix extensively)

is this an issue with the most recent monox  version too? Using older MonoX (v4.9.40.4845 [12/25/2013], DB v4.7.3842)
This content has not been rated yet. 
2793 Reputation 345 Total posts


3/20/2017 6:21:39 PM
I notice the issue here too, if I remove trailing / from this topic url
it gives 404 error (I see no custom 404 page btw, just the browser's 404 in Edge)

This content has not been rated yet. 
2793 Reputation 345 Total posts


3/21/2017 10:39:15 AM

One solution to this problem is to create 2 rewrite rules in your web.config one with a trailing slash and one without. In your case you need to create a second one without a trailing slash.

This content has not been rated yet. 
2218 Reputation 300 Total posts


3/21/2017 11:02:18 AM
aren't too many rules slowing down the system? my 2nd rule seems to work when trailing / is missing, but doesn't work when it is present. How come? The regex pattern I use there was created from the 1st one and I use a (/...)? so I'd expect it to cover both cases. However it doesn't work with the / and I seem to also need the 1st rule (the original one). Can't I merge the two rules somehow?
  I really don't get the syntax being used there for rewriting urls, think I had read you were using some 3rd-party library instead of the rewrite system Microsoft added later on to Is there any doc for it?

Moreover there are many other rules there related to editing a blog post etc. which I wonder if is needed to also cover in case of missing final /
If those other blog-related urls I saw at the rewrite rules section always have ?... or other params at the end (is this the case?), it is less probable that user would remove the / before the params by accident (since / is not at the very end of the url in that case), so I should be safe with fixing just this one rule
This content has not been rated yet. 
2793 Reputation 345 Total posts


3/21/2017 3:09:51 PM
Hi Zoomicon,
MonoX uses a custom module for rewriting, but the syntax is the default syntax used for regex replacement in .NET.

Have you tested your regex, because there are a few cases that might not match as you expect it:
1. ^(.*)/(.*)/post/(.*)/(.*)/(.*)(/(\?(.+))?)?$ - this will match a trailing slash and non-trailing slash, but you won't be able to match query parameters in case of a non-trailing slash URL
2. regex engine is greedy by default which means when your regex is used, the match indices will change depending if the URL has a trailing slash or not - means you should either update the regex to match the slugs correctly, or change the "to" portion of the rewrite rule

See for yourself on

Enter your regex in the pattern field, url in input field and the "to" portion of rewrite URL in the replace matches with... field and then observe the regex matches on the split list tab as you add/remove the trailing slash and/or query string.

Looking at your example, regex
and replacement string 

could work as intended, but please test your edge cases as well.


This content has not been rated yet. 
345 Reputation 61 Total posts