none
How to Implement Url Rewriting for SharePoint?

    Question

  • I'd need to setup Url Rewriting for my SharePoint 2010 application which is hosted in IIS 7.0.

    What is needed is to rewrite this url {0} to {1}:

    {0}: http://myserver:4000/sharepointSitename/json

    {0}: http://myserver:5000/webserviceName/json

    I installed Url Rewrite module and added a rule for this to be done but it doesn't work:

    http://www.iis.net/download/urlrewrite

    My question is should it work at all with this? or I'd have to create a custom http module to do this?

    Many thanks in advance.

    • Moved by Clayton Cobb Sunday, January 09, 2011 4:58 PM Programming question (From:SharePoint 2010 - General Questions and Answers)
    Sunday, January 09, 2011 4:32 PM

Answers

  • I think the issue here is that JavaScript intentionally doesn't support cross-domain calls, since if it did it would be a big security hole which lots of unscrupulous websites would exploit. I don't think you'll be able to use URL rewriting to get round this. 

    Also note that although there isn't a Technet page which spells it out clearly for SharePoint 2010, for 2007 Microsoft were clear that rewriting using asymmetric paths was not supported - see 'Reverse proxy publishing' section on http://technet.microsoft.com/en-us/library/cc261814(office.12).aspx

    The more normal way of solving the domain issue is to have a web service hosted on the same URL as the calling site, which in turn calls the actual web service (located wherever) and forwards the results back. Is this an option for you?

    HTH,

    Chris.

     

     


    Chris O'Brien | SharePoint MVP | www.sharepointnutsandbolts.com
    Monday, January 10, 2011 10:44 PM

All replies

  • Sunday, January 09, 2011 5:13 PM
  • Please note that URL rewriting in SharePoint is not supported. From what you're writing it seems like you might succeed with using URL redirect instead of rewriting. Is there anything specific that you're having problems with?
    w: http://blog.mastykarz.nl | t: @waldekm | c: http://mavention.codeplex.com | c: http://mavention.nl
    Sunday, January 09, 2011 6:20 PM
  • Hi again,

    Is there any way you could use Host-Named Site Collections? http://technet.microsoft.com/en-us/library/cc424952.aspx

    You can create Host Named Managed Paths through PowerShell:

    New-SPManagedPath http://host.header.site.url -HostHeader
    
    And then you can create a site collection at that Url through PowerShell or the API:

    New-SPSite http://host.header.site.url -OwnerAlias DOMAIN\username -HostHeaderWebApplication http://servername
    

    or

    SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://www.contoso.com"));
    SPSiteCollection sites = webApp.Sites;
    SPSite Site = null;
    Site = sites.Add("http://hoster.contoso.com", "Site_Title", "Site_Description", 1033, "STS#0", "contoso\owner", "Owner_Display_Name", "Owner_Email", "contoso\secondaryowner, "Secondary_Owner_Display_Name", "Secondary_Owner_Email", true);
    

    Hope this helps!

     


    joel
    Joel's SharePoint Architect Blog
    joelblogs.co.uk
    Want SharePoint Training?
    Sunday, January 09, 2011 6:40 PM
  • Thanks Joe for your replies. yea, that's a great link.

    I created a test site with few htm files (home.htm, redirectto.htm and rewriteto.htm) and tried configuring the url rewriting and redirecting both for them but had no success yet so I tend to think there is something wrong with my IIS settings that it doesn't work rather than a sharepoint issue..

    Do I need to do configure anything else after installing ARR? e.g. adding a new ISAPI Filter, etc?

    Thanks,

     

    Monday, January 10, 2011 10:38 AM
  • I've got url redirection working (it was a minor pattern issue) but still url rewriting doesn't work.

    I turned on Fiddler and saw that it gives 401 and 404messages and they're for not authorized access and Not Found.

    I'd guess the security credentials of the original request is not sent to the rewrite to url. Is there any config for this?

    The pattern I'm using to test is: ^(.*/)?home\.htm$ (which is the home.htm page)

    and Rewrite Url is: http://www.google.com

    If I use a Rewrite url which contains {R:0} or {R:1} it works though but it means it can only rewrite to the urls on the same site? which is not what I need.

    Thanks,

    Monday, January 10, 2011 11:16 AM
  • I think I'd need to configure reverse proxy with url rewriting: http://learn.iis.net/page.aspx/659/reverse-proxy-with-url-rewrite-v2-and-application-request-routing/

    something new to learn :)

    Monday, January 10, 2011 3:02 PM
  • Thanks Waldek,

    No url redirecting can't help my scenario. I'd need both urls to be trusted.

    my scenario is that, a javascript function on a sharepoint page, needs to make web service calls to a web service which is on another server and currently it gives me access denied error message that I hope by url rewrite and reverse proxy it should be working.

    Monday, January 10, 2011 3:05 PM
  • I think the issue here is that JavaScript intentionally doesn't support cross-domain calls, since if it did it would be a big security hole which lots of unscrupulous websites would exploit. I don't think you'll be able to use URL rewriting to get round this. 

    Also note that although there isn't a Technet page which spells it out clearly for SharePoint 2010, for 2007 Microsoft were clear that rewriting using asymmetric paths was not supported - see 'Reverse proxy publishing' section on http://technet.microsoft.com/en-us/library/cc261814(office.12).aspx

    The more normal way of solving the domain issue is to have a web service hosted on the same URL as the calling site, which in turn calls the actual web service (located wherever) and forwards the results back. Is this an option for you?

    HTH,

    Chris.

     

     


    Chris O'Brien | SharePoint MVP | www.sharepointnutsandbolts.com
    Monday, January 10, 2011 10:44 PM