Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Looks like IIS might not know how to handle a request with an empty extension.

Right click on the website and choose "Properties". Click "Configuration..." on the "Home Directory" tab. Look at the "Application Extensions" and try adding an empty or wildcard extension.

You shouldn't be putting exact user searches in the query string like that... you should UrlEncode them. That will solve the problem.

In windows, file names cannot end with a '.' I think all problems stem from there, ie IIS doesn't know what to do with it, so it never gets as far as the ASP.NET error handler and gets handles by the default IIS 404 page.

Most search engines (well Google anyway) exclude punctuation from queries, and I think yours should too.

EDIT: It falls over because it has no file type, even the Microsoft site falls over look http://www.microsoft.com/en/us/fallover. but you can modify the default error files (live somewhere like C:\WINDOWS\help\iisHelp\common) or change it completely.

Check this one out: Configuring Custom Error Messages (IIS 6.0)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top