II7 Rules [Answered]RSS

5 replies

Last post Apr 28, 2020 01:25 PM by brucey54

  • II7 Rules

    Apr 24, 2020 09:51 AM|brucey54|LINK

    I’m trying set a redirect rule for a specific url, but it’s not working.

    Basically I’m trying to obscure the admin page url to something else i.e.

    If you type the url: mysite/admin

    You would be redirected back to the home page and

    If you typed the url: mysite/admin/hiddenAdminPage

    You would then be redirected to the admin page…

    I'm testing it on my local machine running Microsoft studio 2019 IIS express

     <rewrite>
          <rules>
    <rule name="[RULE NAME]" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny" trackAllCaptures="false"> <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[localhost:56973/umbraco/admin]" /> <add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.[localhost:56973/umbraco/admin]" /> </conditions> <action type="Redirect" url="http://[localhost:56973/]" redirectType="Permanent"/> </rule>
    <rule name="[RULE NAME 2]" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny" trackAllCaptures="false"> <add input="{HTTP_HOST}{REQUEST_URI}" pattern="[localhost:56973/umbraco/hiddenAdminPage]" /> <add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.[localhost:56973/umbraco/hiddenAdminPage]" /> </conditions> <action type="Redirect" url="http://[localhost:56973/umbraco/admin]" redirectType="Permanent"/> </rule>
    </rules> </rewrite>

  • Re: II7 Rules

    Apr 24, 2020 04:48 PM|lextm|LINK

    brucey54

    I’m trying set a redirect rule for a specific url, but it’s not working.

    They won't work as they are not valid rules with correct regular expressions.

    If you want to learn something useful, get started from https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference

    Lex Li
    Affordable IIS Consulting Services at https://support.lextudio.com/services/consulting.html
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: II7 Rules

    Apr 28, 2020 09:51 AM|samwu|LINK

    Hi bruce54,

    brucey54

    If you type the url: mysite/admin

    You would be redirected back to the home page and

    If you typed the url: mysite/admin/hiddenAdminPage

    You would then be redirected to the admin page

    There is a problem with your rules. I made demo for you as a reference.

    <rules>
    
                    <clear />
    
                    <rule name="redirect1" stopProcessing="true">
    
                        <match url="^admin/(.+)$" />
    
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    
                        <action type="Redirect" url="admin/" />
    
                    </rule>         
    
                    <rule name="redirect" stopProcessing="true">
    
                        <match url="^admin$" />
    
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    
                       <action type="Redirect" url="/" />
    
                    </rule>           
    
                </rules>

    The result:

    Best regards,

    Sam

    .NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
  • Re: II7 Rules

    Apr 28, 2020 11:42 AM|brucey54|LINK

    Thanks samwu, I can't get this to work see code below;

     <rewrite>
          <rules>
    
            <clear />
            <rule name="redirect1" stopProcessing="true">
              <match url="^localhost:56973/admin/(.+)$" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
              <action type="Redirect" url="http://localhost:56973/umbraco/" />
            </rule>
    
            <rule name="redirect" stopProcessing="true">
              <match url="^localhost:56973/umbraco$" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
              <action type="Redirect" url="/" />
            </rule>
            
          </rules>
        </rewrite>

  • Re: II7 Rules

    Apr 28, 2020 01:11 PM|lextm|LINK

    Lex Li
    Affordable IIS Consulting Services at https://support.lextudio.com/services/consulting.html
    ---------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: II7 Rules

    Apr 28, 2020 01:25 PM|brucey54|LINK

    Thanks lextm,  i got it to working with the following code :)

    I can this be improved?

    <rewrite>
          <rules>
    
            <clear />
            <rule name="redirect1" stopProcessing="true">
              <match url="^admin$" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
              <action type="Redirect" url="http://localhost:56973/umbraco/" />
            </rule>
    
            <rule name="redirect" stopProcessing="true">
              <match url="^umbraco$" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
              <action type="Redirect" url="/" />
            </rule>
            
          </rules>
        </rewrite>