Currently I am using the web hosting service provided by another company. It uses IIS 7/IIS 8 and allows customers to modify web.config
according to their needs.
Suppose I have set up two valid URL:
Now, when I try to access http://abc.example.com
, HTTP Error 403.14 - Forbidden
is returned; and if I then try to access http://www.example.com/abc
, HTTP Error 404.0 - Not Found
is returned.
How can I configure web.config
such that users will be redirected to http://www.example.com
when they are trying to access an invalid URL?
I have tried to use the snippet provided by the company but without success:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>