Forum Discussion

Bob_10976's avatar
Bob_10976
Icon for Nimbostratus rankNimbostratus
Jul 26, 2012

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

 

 

8 Replies

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus
    Use HTTP::host to verify the domain name. Keep in mind that www.domain.com and domain.com are different hosts.

     

     

    To 'mask' the request so that "/file" is sent to the servers as "/file.aspx" you can use HTTP::uri (concatenate .aspx).

     

    However, keep in mind that you'll need a way to handle legitimate requests for folders (going to the default page); you don't want to add .aspx to those requests.

     

     

    In the end, it may be better to use the .NET feature for serving pages without the extension.

     

     

  • Arie,

     

     

    Thanks for the reply, however I'm not completely following you. Can you provide me with an example of the irule itself and can you expand on the "However, keep in mind that you'll need a way to handle legitimate requests for folders (going to the default page); you don't want to add .aspx to those requests." comment.

     

     

    Thanks,

     

    Bob

     

     

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus
    Bob,

     

     

    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

     

     

     

     

     

     

     

  • Thanks Arie....

     

     

    I believe you are correct, the rewrite will need to handle both request but display as you have in your example.

     

     

     

    Thanks,

     

    Bob

     

     

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    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.

  • The IIS URL Rewrite function is being considered as an option, but I wanted to review this first.

     

     

    Any chance you could provide me with an example irule of how you have that laid out, or point me in the right direction of one I may be able to reivew.

     

     

     

    Thanks again,

     

    Bob

     

     

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus
    No 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

     

     

     

     

     

  • As 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.

     

     

    Aaron