locked
Redirect only specific sub site not root/other sub sites RRS feed

  • Question

  • User-608635125 posted

    I am trying to use IIS URL rewrite to redirect only specific sub site documents and it should not redirect other sub site (OR) root site documents (These are SharePoint sites).

    Example: Redirect documents from 

    https://test.abc.com/subsite1/Documents/mydocument.pdf?Web=1   document URL's to https://xyz.abc.com

    And it should not redirect, if source url contains other sub site/root site document url's like below

    https://test.abc.com/Documents/mydocument.pdf?Web=1  (OR) https://test.abc.com/subsite2/Documents/mydoc.pdf?Web=1

    using below code in web config: this is not redirecting as expected with this pattern (pattern="^test.abc.com\/subsite1\/")


    <rule name="subsite1 Redirection" stopProcessing="true">
    <action type="Redirect" url="https://xyz.abc.com" appendQueryString="false" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^test.abc.com\/subsite1\/"/>
    </conditions>
    <match url="\.(pdf|txt|xls|doc|ppt|xlsx|docx|pptx)" />
    </rule>

    Thursday, January 30, 2020 12:49 PM

All replies

  • User690216013 posted

    <add input="{HTTP_HOST}" pattern="^test.abc.com\/subsite1\/"/>

    That's a typical mistake, as the HOST header won't contain subsite1. Try to add another condition to check that.

    Also learn how to use FRT to debug your rules, https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules 

    Thursday, January 30, 2020 4:34 PM
  • User-72702933 posted

    Hi neerubee123 ,

    The http_host will just match the domain, if you want to check the subsite1, you should use PATH_INFO.

    More details, you could refer to below url rewrite rule:

    <rule name="subsite1 Redirection" stopProcessing="true">
    <action type="Redirect" url="https://xyz.abc.com" appendQueryString="false" />
    <conditions> 
    <add input="{HTTP_HOST}" pattern="^test.abc.com"/> 
    <add input="{PATH_INFO}" pattern="subsite1"/> </conditions> <match url="\.(pdf|txt|xls|doc|ppt|xlsx|docx|pptx)" /> </rule>



    Best Regards,

    Brando

    Friday, January 31, 2020 6:38 AM
  • User-608635125 posted

    I tried above which you posted but there is one case where it is failing.

    If user have some bookmarks like this: https://test.abc.com/Document%20Library/sample.xlsx?Web=1 is also redirecting and expectation is it should not redirect. It means, root site documents should not redirect.

    Thank you.

    Thursday, February 6, 2020 11:57 AM