FungyBytes
FungyBytes

Reputation: 413

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.

Upvotes: 1

Views: 2802

Answers (2)

pseudocoder
pseudocoder

Reputation: 4392

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.

Upvotes: 1

pseudocoder
pseudocoder

Reputation: 4392

This should work and also be much simpler. You don't need URL rewriting, just HTTP redirect.

As for the 403, does the IIS application pool have read access to the folder at the root of your site?

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpRedirect enabled="true" destination="www.B.com" httpResponseStatus="Permanent" />
    </system.webServer>
</configuration>

Upvotes: 0

Related Questions