HTTP to HTTPS redirect for a specific domain through web.config
I'm trying to do a HTTP to HTTPS redirect on a GoDaddy web hosting platform. I have the Windows hosting platform and I'm editing the web.config file. There are multiple domains under this hosting account, and I'm trying to do the redirect for only ONE domain and its subdomains.
Example:
- 5 domains:
domain1.example,domain2.example, etc... and each domain may have subdomains
Desired behaviour:
*.domain1.exampleredireced tohttps://*.domain1.example(with or without www)- include a wildcard in front of the domain, to handle any sub-domains
This is what I started with, which will redirect every domain from HTTP to HTTPS, and it works properly:
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="HTTPS" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://HTTP_HOST/R:1" />
</rule>
Now I tried to make it for a specific domain only, but I really have no idea how to write this myself. Instead I have put together some stuff I found online. I find all the +? and A-Za quite confusing.
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(https?://(.+?.)?domain1.example(/[A-Za-z0-9-._~:/?#[]@!$&'()*+,;=]*)?)" />
<conditions>
<add input="HTTPS" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://HTTP_HOST/R:1" />
</rule>
But this results in a 500 (internal server) error.
<match url="(https?://(.+?.)?domain1.example
I believe the url attribute matches URL-paths only, not the absolute URL, so this will never match. But if it did match, it's also matching https, which is not what you require.
Try just adding another condition to your original rule that checks the HTTP_HOST for the specific domain. For example:
<add input="HTTP_HOST" pattern="^([a-z]+.)?domain1.example$" />
Comments
Post a Comment