Search code examples
asp.nethttp-redirectiis-7http-status-code-301

Permanent 301 redirect for ASP.NET IIS7


Im trying to figure out how to setup a 301 permanent redirect for a website that is placed on a Microsoft-IIS/7.0 type server. So let's say I have domain www.A.com and I want to redirect this to www.B.com I could use something like the following in my web.config file:

<configuration>
<system.webServer>
<rewrite>
   <rules>
      <rule name="Redirect to WWW" stopProcessing="true">
        <match url="A.com" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^www.B.com$" />
   </conditions>
   <action type="Redirect" url="http://www.B.com/{R:0}"
        redirectType="Permanent" />
   </rule>
 </rules>
</rewrite>
</system.webServer>
</configuration>

When placing the web.config in the root directory, the server responds:

403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied.

Any suggestion why this 403 error is given?

Thanks in advance.


Solution

  • If you are getting a 403 error with a plain (default) web.config and totally vanilla Default.aspx, then there is a configuration problem with IIS. Most likely the app pool does not have rights to the base folder for the website. Sounds like you're in a hosted situation so contact the system administrator.