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.

Do I need a URL rewrite to remove trailing spaces from incoming URLs (they throw 404 errors)  (Mono Support )

Viewed 22990 time(s), 4 post(s) 10/20/2014 4:58:33 PMby Zoomicon

Related topics

Zoomicon

Zoomicon

10/20/2014 5:02:47 PM
At
http://ec.europa.eu/languages/inspire/0810-clipflair_en.htm
the European Commission have featured the ClipFlair project :-)

However, at the end of their page they had a link to the social network part of the ClipFlair project, with an extra encoded space at the end, that is http://social.clipflair.net/%20 which was showing an error page (not found) to the visitor who clicked that link. I told them to correct it, but now they seem to be going to the same URL with the extra space at the end, just not encoding it to %20 (!!!). Obviously you can't type a URL with spaces at the end in say Mozilla Firefox, it trims it, but seems that if an anchor tag has such a link, they try to go to it and most importantly they don't encode it on the address bar automatically, so user sees "http://social.clipflair.net " on the addressbar (without the double-quotes) and they don't understand why they see a missing content page (404 I guess it is). So it looks a bit worse than before now after they "fixed" their link :-(

So, my question is, can IIS or ASP.net be set to trim such spaces from the end of incoming URLs, or could some URL rewrite be written to fix it? (I'm not familiar with the rewrite engine MonoX uses, so if you can provide a copy-pasteable suggestion to place in web.config I'd be grateful)

UPDATE: seems I was wrong on my evaluation of the issue above, they have fixed only the text, not the URL at the anchor tag, that's why it still fails (Firefox does remove trailing spaces from URLs fine if they're in the href of the anchor tag). So I need to remove %20 from the end of the URL, they have in their HTML:

<a href="http://social.clipflair.net/%20" target="_blank">ClipFlair website



cheers,
George
This content has not been rated yet. 
2793 Reputation 345 Total posts
mzilic

mzilic

10/21/2014 10:10:56 AM
Hello,

The problem seems to have been resolved by fixing the link on the site you mentioned. However, if you'd like to resolve the problem by using the rewrite module you could use an if statement to conditionally do a 301 redirect for certain links:
<if url="regex expression goes here" ignorecase="true">
    <redirect url="^(.*)$" to="http://my-domain.com" />
</if>  
Regards,
Mario
This content has not been rated yet. 
2218 Reputation 300 Total posts
GeorgeBirbilis13

GeorgeBirbilis13

10/21/2014 12:02:11 PM
actually the URL at the bottom of their page is still broken and has %20 at the end [its text shows ok, but the anchor href is wrong] (the others in the page were ok from the beginning).

So, if I get it correctly I should add in web.config the rule

<if url="^.*(%20)+$" ignorecase="true">
    <redirect url="^(.*)(%20)+$" to="$1" />
</if> 

btw, web.config supports splitting in many files the configuration, so maybe you should split such parts like the rewrite rules to separate files to ease administration
This content has not been rated yet. 
211 Reputation 26 Total posts
mzilic

mzilic

10/22/2014 10:21:27 AM
Hello,

That should work you could try as well something like this for example:
<if url="^.*( )+$" ignorecase="true">
    <redirect url="^(.*)( )+$" to="http://my-domain.com" />
</if>  
btw, web.config supports splitting in many files the configuration, so maybe you should split such parts like the rewrite rules to separate files to ease administration
Thanks for the suggestion, we are aware of the option. We've opted for a flat web.config approach to allow all of the options to be available to users in one place. You can always easily add the custom configurations on your own custom MonoX project.

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