GoDaddy — Implementing Url Rewrite Rule with Windows Hosting
I recently setup hosting on GoDaddy, and I realized after the fact that Linux has case sensitivity with URLs. I couldn’t predict if my editors would be matching image file casing with the actual filenames. So I had to switch to Windows Hosting.
After doing this, I made my site serve up under SSL. By default, your site runs under HTTP. By adding SSL, your site will serve up your site with both HTTP and HTTP requests. It is not ideal to have both respond, since the intention of installing SSL is to make your site secure.
The standard practice is to correct this is to put in place a mechanism to automatically redirect all HTTP traffic to HTTPS. If you have a Linux hosting environment, you can create an .htaccess file with the rewrite rule. In Windows, this occurs by use of a web.config.
There is a GoDaddy knowledgebase article that I’ll refer to:
https://in.godaddy.com/help/redirect-my-website-to-https-in-pleskwindows-27873
Since I am using a Windows hosting environment, I will be using the Plesk panel. Under Linux, this would be the cPanel.
Create a web.config in a simple text editor and pasted in the suggested code. Because this file is in an XML format, you’ll want to add in the <?xml> tag first. The end result is as shown:
Save this file and upload it to your web root directory.
Note: if you find the redirect isn’t working, you’ll want to go into Plesk admin -> Hosting Settings -> Web Server Settings and make sure the site isn’t “Requiring SSL”. If this option is selected, IIS will first capture traffic and redirect the user to a 403 Forbidden page, if the user traffic is coming in as HTTP. You have to disable this option, and let the application be accessed. Your web.config will then redirect traffic to the HTTPS version.
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <rewrite> <rules> <clear /> <rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
Here is a decision tree of the process to help you understand:
Originally published at codegabber.com on May 4, 2018.