Add HTTPS redirect rewrite rule to web.config

jxharding's Avatar

jxharding

13 Oct, 2017 07:50 AM

I've done variable replacement and Transforms via Octo on various occasions, but this is a bit different. It is inserting complete section to the existing

For development purposes in Visual Studio, we can't have an HTTP to HTTPS redirect, but we need it when the site is deployed. In other words this section does not exist during development.

I am asking assistance in how to add this section to the config please:

 <rewrite>
    <rules>
        <clear/>
        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
            <match url="(.*)"/>
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found"/>
        </rule>
    </rules>
</rewrite>

The attached file shows an example of a demo web.config, and how that demo looks with the rewrite rule added.

I have seen multiple help pages on using powershell for redirect rules, but can't get to grips on how to add this specific rewrite rule.

Can this be done in powershell ? can it be done in Octo via transforms?

  1. Support Staff 1 Posted by Shane Gill on 16 Oct, 2017 12:10 AM

    Shane Gill's Avatar

    Hi,

    Thanks for getting in touch.

    I think your best bet is to use configuration transforms to add that section to your config. There is documentation here on configuration transforms, you want the "insert" transform: https://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx

    Create a transform file beside your config file and get Octopus to do the transformation when you deploy: https://octopus.com/docs/deploying-applications/configuration-files...

    Hope this helps.

    Cheers,
    Shane

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • 20171013_example_.txt 1.66 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac