locked
Web.config Redirects RRS feed

  • Question

  • User-1941296693 posted

    Hi,

    • I want to redirect the homepage from an old domain to a new domain
    • I want to redirect another page 'page1' to the corresponding page on the new site
    • The rest of the pages can be redirected to the new domain

    Can anyone help me with the code?

    thanks you

    M

    Saturday, May 5, 2018 6:01 PM

All replies

  • User753101303 posted

    Hi,

    Do you have access to the IIS configuration? For now it seems using https://docs.microsoft.com/en-us/iis/configuration/system.webserver/httpredirect/ is enough for what you need.

    Sunday, May 6, 2018 11:29 AM
  • User-1941296693 posted

    frown no I don't have access to IIS, that's why I'm trying to do it in the web.congif file.

    any ideas?

    Monday, May 7, 2018 11:13 AM
  • User283571144 posted

    Hi michaelcode,

    frown no I don't have access to IIS, that's why I'm trying to do it in the web.congif file.

    any ideas?

    According to your description, I suggest you could try to add url rewrite config in web.config file.

    I suggest you could add below config codes inside  <system.webServer>.

    Notice:Paste the following code at the new line, replacing [RULE NAME], [OLD URL] and [NEW URL] with the appropriate information (see Rule Variations below). When putting in the [OLD URL], don't include the http:// as that will not work.

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

    More details about how to create url rewrite rule, I suggest you could refer to below codes:

    https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    Best Regards,

    Brando

    Tuesday, May 8, 2018 6:24 AM