HTTP to HTTPS redirect for a specific domain through web.config

HTTP to HTTPS redirect for a specific domain through web.config - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the HTTP to HTTPS redirect for a specific domain through web.config error on your web browser. Problem :


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.example redireced to https://*.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.


Solution :


<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$" />

We hope that this article has helped you resolve the redirects, https, godaddy error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=