Forum Discussion
Rewrite URI removing file extension
Hello all…
We host about 20 or so sites in our SharePoint 2010 environment and all of them utilizes the same virtual server on the LTM. I have one site that would like to remove the “.aspx” extension from the URI for each and every page that is requested. I would like to do this via the LTM iRules using a rewrite irule, if possible. My problem comes in where there are other sites associated to this virtual server I do not want them effected, also since there will be a lot of pages with different names I’m not sure how to set this up in a “wildcard” type scenario.
Below is an example of what we have and what we’d like to do.
What we have currently
http://domainname.com/pages/default.aspx
http://domainname.com/pages/mypage.aspx
etc..
What we’d like to see:
http://domainname.com/pages/default
http://domainname.com/pages/mypage
etc..
Any suggestions on the proper rewrite irule to apply to just the domainname.com site?
Thanks,
Bob
- ArieAltostratusUse HTTP::host to verify the domain name. Keep in mind that www.domain.com and domain.com are different hosts.
- Bob_10976Nimbostratus
Arie,
Thanks,
- ArieAltostratusBob,
No problem. However, first I'd like to fully understand the problem.
Is the requirement to handle both requests with and without the extension .aspx?
In other words, should requests like this:
http://www.domain.com/info/events.aspx
http://www.domain.com/info/events
Both request the following from the server:
http://www.domain.com/info/events.aspx?
(but display http://www.domain.com/info/events in the browser's address bar?)
Arie
- Bob_10976Nimbostratus
Thanks Arie....
- ArieAltostratus
The best way to do this is on the web servers (IIS URL Rewrite - http://www.iis.net/download/urlrewrite ).
Rule for the IIS URL Rewrite module:
<< the text editor of the forum is 'eating' the code - I have sent a message to the support guys...>>To achieve this with an iRule (for your scenario):1)Check the host (domain)2)Check to see whether the request has a file extension. If it does and it's not aspx, leave the request alone.3)If the extension is aspx, consider redirecting it (301, not 302) to the same URL without the extension. Retain the querystring.4)If the request doesn't have a file extension, verify that it's not a request for the default page in a folder. For instance, a request for /events might well be intended to return /events/Default.aspx. It wouldn't do to rewrite it to /events.aspx.5)If there's no extension and it's not a request for the default page in a folder, rewrite the request so the extension .aspx is appended. - Bob_10976Nimbostratus
The IIS URL Rewrite function is being considered as an option, but I wanted to review this first.
Thanks again,
- ArieAltostratusNo problem!
1)
if { [HTTP::host] equals "domain.com" } {
logic here
}
2)
if { [HTTP::path] contains "." } {
logic here
}
3)
This is optional. Forcing a redirect to the URL without the extension has the potential to break functionality, though.
4)
This is where it gets interesting. The best way would probably be to use a sideband connection to check whether the response would be a 404. If it is you can request the resource with the added ".aspx". If the response is anything else you should send it on as the original request.
Normally I'd check for a 200, but there's a slight risk that the app requires certain parameters (or viewstate) and would respond with a 500.
To make matters worse, by default .NET responds to both a server error (500) and Not Found (404) with a 302 (redirect to the appropriate error page, which in turn yields a 200)... Brilliant Microsoft 'logic'!
Unfortunately, I don't have enough time right now to hammer out the code for this part.
5)
HTTP::uri [HTTP::path].aspx
Note: you'd want to add some mechanism to deal with querystrings
- hooleylistCirrostratusAs Arie said, this is better handled on the application itself. That said, what is your goal in hiding the file extensions? Malicious users will still be able to identify the OS via other OS and web app fingerprinting methods.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com