locked
IIS 301 Redirection RRS feed

  • Question

  • User167598524 posted

    I stuck in redirection process using IIS. I want to redirect URL to another one. But the main point here is that the URL can be from Http or Https. For example:

    URL A: http://www.example.com - redirect to https://www.example.org

    URL B: https://www.example.com - redirect to https://www.example.org

    How can I achieve this scenario?

    What I have done is just redirecting old URL coming from https protocol to new domain. However, if the old url comes with http protocol then it wont redirect. I want to redirect old URL to new one, whether it comes with http or https.

    Thanks for help.

    Thursday, July 26, 2018 11:57 AM

All replies

  • User167598524 posted

    This is not what I want dear.

    Do 1 thing, Just create a rule which will redirect you to other url from old url. And try to access old url by both, Https and Http and see do you get same result in both or not.

    Thanks. 

    Thursday, July 26, 2018 1:03 PM
  • User-369506445 posted
    <rewrite>
      <rules>
        <rule name="Redirect oldexample.com to newexample.com" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
      <add input="{HTTPS}" pattern="^www\.oldexample\.com$" />
    <add input="{HTTP_HOST}" pattern="^www\.oldexample\.com$" />
    <add input="{HTTP_HOST}" pattern="^oldexample\.com$" />
    </conditions>
    <action type="Redirect" url="http://www.newexample.com/{R:1}" />
    </rule>
    </rules>
    </rewrite>

    Thursday, July 26, 2018 1:26 PM
  • User167598524 posted

    Thanks for the reply.

    And what about below scenario:

    1- (http or https)://www.example.com/ar/brand/apple  moved to www.newurl.com/ar/brand/apple

    2- (http or https)://www.example.com/ar/brand/bosh  moved to www.newurl.com/ar/brand/bosh

    Thursday, July 26, 2018 1:42 PM
  • User-369506445 posted

    Please try

    <rewrite>
      <rules>
        <rule name="Redirect oldexample.com to newexample.com" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
            <add input="{HTTPS}"      negate="true" pattern="^www\.oldexample\.com$" /> 
            <add input="{HTTP_HOST}"  negate="true" pattern="^www\.oldexample\.com$" /> 
            <add input="{HTTP_HOST}"  negate="true" pattern="^oldexample\.com$" /> 
          </conditions> 
    <action type="Redirect" url="http://www.newexample.com/{R:1}" redirectType="Permanent"  /> 
       </rule> 
     </rules> 
    </rewrite>

    Thursday, July 26, 2018 1:59 PM
  • User753101303 posted

    Hi,

    if the old url comes with http protocol then it wont redirect

    So you does an explicit check on that ? It seems to me you should be able to redirect www.example.com (regardless of using http or https) to https://www.example.org ? 

    Having two rules might be more convenient. I suspect the problem could be that you try to use the same rule to also handle http://www.example.org to https://www.example.org redirection ?

    Thursday, July 26, 2018 2:18 PM
  • User167598524 posted

    I have around 100 redirection. What is the best way to do that keeping in mind that the new url structure is different that the old one like:

    (http or https)://www.oldurl.com/ar/bosch to https://newurl/ar/home-appliances/brands-1/bosch.html

    (http or https)://www.oldurl.com/ar/apple to https://newurl/ar/home-appliances/shop-apple/apple.html

    Hope you get it.

    Thursday, July 26, 2018 2:22 PM
  • User-369506445 posted

    Did you try my last post?

    Thursday, July 26, 2018 2:24 PM
  • User167598524 posted

    Yes and that only redirect using the structure of old url. However, new url have different structure than old one.

    Yes that is the one solution for this. But I dont want to do like this. There are 100 of redirection rules already which worked perfectly with https.

    Thursday, July 26, 2018 2:30 PM
  • User-369506445 posted

    I wrote the sample based on your last need that was how to rewrite the old URL to new

    Now you have different structure, you can use my sample with different rules, below is a good sample that shows how to rewrite URLs with different structure, please follow below link

    http://www.iis.net/learn/extensions/url-rewrite-module/using-rewrite-maps-in-url-rewrite-module

    I hope it can be helpful 

    Thursday, July 26, 2018 2:50 PM