URL Redirect with an exceptionRSS

5 replies

Last post Jul 09, 2019 08:39 AM by Jalpa Panchal

  • URL Redirect with an exception

    Jul 09, 2019 01:45 AM|stc2000|LINK

    Hi, I am new to URL Rewrites and Redirection. Basically I have setup my old web site to redirect to my new web site.

    I used a wildcard pattern (.*) on IIS 10 URL rewrite module with the following condition -  {HTTP_POST} matches www.redirectedsite.com$ and {HTTP_POST)  redirectedsite.com$ and an action to "redirect" to my new site https://www.newsite.com.

    I have also created a DNS A and CNAME record as an alias to the new site:

    DNS Records

    Name   Type       TTL   Value

    @          A           300   (newsite IP address)

    www     CNAME  300   www.newsite.com

    The redirection works and any URL I type in the browser for the old site is redirected to new site, although I need to make an exception for one folder on the redirected site www.redirectedsite.com/subfolder but when I setup another URL Redirect rule for this it doesn't work? Not sure whether I should be creating a new rule for this or not? Any help would be much appreciated as I'm not sure how an exception would work as everything is redirected at the moment.

    Regards

    Alex

  • Re: URL Redirect with an exception

    Jul 09, 2019 02:17 AM|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: URL Redirect with an exception

    Jul 09, 2019 02:36 AM|Jalpa Panchal|LINK

    Hi Alex,

    You could use below rewrite rule to redirect old domain to new domain with exception:

     <rule name="Redirect all to different domain" enabled="true" stopProcessing="true">
                        <match url=".*" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^www.sample1.com$" />
                            <add input="{REQUEST_URI}" pattern="s2" negate="true" />
                        </conditions>
                        <action type="Redirect" url="http://www.sample2.com/{R:0}" redirectType="Permanent" />
                    </rule>

    Replace the name of the folder instead of s2.

    Regards,

    Jalpa

    .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: URL Redirect with an exception

    Jul 09, 2019 07:35 AM|stc2000|LINK

    Thanks for the feedback I'll try this 

  • Re: URL Redirect with an exception

    Jul 09, 2019 08:37 AM|stc2000|LINK

    Hi Jalpa,

    Thanks for your help, I tried the above using (change site names):

    <rule name="site1.com.au" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="^www.site1.com.au$" />
    <add input="{REQUEST_URI}" pattern="awards" negate="true" />
    </conditions>
    <action type="Redirect" url="https://www.site2.com.au/ {R:0}" />
    </rule>

    and I get a result of: 

    https://www.site2.com.au/%20awards

    which receives a page not found error, thanks again, could it be the DNS causing this?

    Cheers

    Alex

  • Re: URL Redirect with an exception

    Jul 09, 2019 08:39 AM|Jalpa Panchal|LINK

    remove space between the / and {R:0}

    stc2000

    <action type="Redirect" url="https://www.site2.com.au/ {R:0}" />

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