I'm trying to make semantic urls for search pages, but if someone use a search finished in dot, the .net engine return a 404.
The request don't even get to the routing engine, so i think its something related to security or something like that.
For example, the stackoverflow routes also don't work in these case: https://stackoverflow.com/questions/tagged/etc.
You cannot have dots in the end of an URL - no matter if it's a blog post or a forum post, like this one.
Adding the dot to the end of the domain name makes it an absolute fully-qualified domain name instead of just a regular fully-qualified domain name, and most browsers treat absolute domain names as being a different domain from the equivalent regular domain name (I'm not sure why they do this though).
If you are using .NET 4.0 and IIS 7+, you can set this flag in the system.web section of your web.config and it will be allowed:
<httpRuntime relaxedUrlToFileSystemMapping="true" />
I've tested it and it works. Haack has an explanation of it.
Everything after the '.' is the file extension. If that extension isn't mapped to ASP.NET, it won't get handed off to the ASP.NET handler. IIS looks for a static file instead. Hence the 404. If it doesn't add anything (and hard to see how it would), I suggest stripping it out.
When the trailing period is not significant (as it is in the case of https://stackoverflow.com/questions/tagged/etc.) you can use IIS's URL Rewrite module to strip the trailing periods.
Pattern: ^(.*[^.])(\.+)$
Rewrite URL: {R:1}
This isn't going to help when throwing away the period is not an option, or there are periods at the end of intermediate path segments, but for the very real use case of dealing with periods being tacked on to URLs by auto-linking algorithms it can help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With