Link to home
Start Free TrialLog in
Avatar of Tomasz Bojarski
Tomasz BojarskiFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to force HTTPS for URLs with specific words in them?

We have a legacy website with some areas for which we want to force HTTPS. It is easy enough to force HTTPS for entire website however we want to be more selective.

What is the best regex to only match specific word in URL and redirect to HTTPS?

Original URL:

http://www.website.com/SPECIFIC_WORD?tid=3363a670-a37a-4b5e-9a08-91c10r78a7f0

Redirect to:

https://www.website.com/SPECIFIC_WORD?tid=3363a670-a37a-4b5e-9a08-91c10r78a7f0

We are using URL rewrite module under IIS 8.5.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tomasz Bojarski

ASKER

Thanks Kimputer,

That worked like a charm. This let's me create multiple rules for specific words. How would I combine these into a single rule? IS there a way to have look for multiple words in "match url" ?

<rule name="Redirect STRING1 to HTTPS" stopProcessing="true">
                    <match url="STRING1?(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
                </rule>
                <rule name="Redirect STRING2 to HTTPS" enabled="true" stopProcessing="true">
                    <match url="STRING2?(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" logRewrittenUrl="true" />
                </rule>

Thanks
Tom
I have combined this into a single rule by adding

<match url ="STRING1?(.*)|STRING2?(.*)|STRING3?(.*)|STRING4?(.*)|STRING5?(.*)" />

Thanks for your help