0

If I try to access http://mydomain.com/sitecore I get a 403 error.

I would instead prefer for IIS to automatically redirect to https://mydomain.com/sitecore.

I added the following rule in RewriteRules.config:

<rule name="Redirect HTTP to HTTPS - Staging Knowledge Sitecore" stopProcessing="true">
    <match url="(.*)mydomain/sitecore"/>
    <conditions>
    <add input="{HTTPS}" pattern="^OFF$"/>
    </conditions>
    <action type="Redirect" url="https://mydomain.com/sitecore" redirectType="Permanent"/>
</rule>

But this doesn't work - http://mydomain.com/sitecore still returns 403.

QUESTION

How do I implement a redirect to HTTPS?

EDIT: the following rule is successfully redirecting the base domain, that is, from http://mydomain.com to https://mydomain.com:

<rule name="Redirect HTTP to HTTPS - Staging URL" stopProcessing="true">
    <match url="(.*)"/>
    <conditions>
    <add input="{HTTP_HOST}" pattern="mydomain.com"/>
    <add input="{HTTPS}" pattern="^OFF$"/>
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent"/>
</rule>
  • 403 is a security error, not a redirect error. Maybe you have IP locking on the site? – Richard Hauer Oct 15 '19 at 0:23
  • @Emanuele Ciriachi might be a copy/paste error, but looks like your match URL is missing the .com . Did you want to only be redirecting to HTTPS for that specific URL? Or everything on that host? – George Tucker Oct 15 '19 at 0:26
  • @GeorgeTucker It was a copy/paste error indeed. I only need to redirect for that specific URL - I have another rule for the base domain that works. Everything on that host would be ideal. – Emanuele Ciriachi Oct 15 '19 at 8:52
  • @RichardHauer I edited the question - I have another rule that successfully HTTPS-redirects the base domain. – Emanuele Ciriachi Oct 15 '19 at 8:55
  • @EmanueleCiriachi - Could it be that you have a Netscalar LB which is returning the 403 response ? – Abhay Dhar Oct 15 '19 at 9:17
1

It seems you have a rule with type="CustomResponse" statusCode="403". So, try placing below rule before CustomResponse rule.

Updated Rule -

<rule name="Redirect HTTP to HTTPS - Staging Knowledge Sitecore" stopProcessing="true">
    <match url="(.*)sitecore"/>
    <conditions>
        <add input="{HTTPS}" pattern="^OFF$"/>
    </conditions>
    <action type="Redirect" url="https://mydomain.com/sitecore" redirectType="Permanent"/>
</rule>
| improve this answer | |
  • Doesn't work, sorry. – Emanuele Ciriachi Oct 15 '19 at 9:07
  • Are you still getting 403 error after adding this rule? – Surya Oct 15 '19 at 9:15
  • also, do you have a rule for CustomResponse code 403? – Surya Oct 15 '19 at 9:17
  • Yes. I enter http://mydomain.com/sitecore and this results in a 403. No, I do not have a CustomResponse. – Emanuele Ciriachi Oct 15 '19 at 9:17
  • can you share all existing rules? – Surya Oct 15 '19 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.