Link to home
Create AccountLog in
Avatar of jkpc21
jkpc21

asked on

IIS 7 Http Redirect Issues

I have IIS 7 installed on my Server 2008 machine. My internal domain name and external website have the same name. Lets say my domain is called "domain1.com"

In my DNS Manager, i have an "A" record set for www to go to "www.domain1.com" which is our external website. This works just fine but requires internal users to type www to get to the website instead of just the domain name. In some of the browsers, the www portion is removed automatically so the user then see the IIS 7 page instead of our website.

I setup a HTTP Redirect in IIS with the following settings. I check the box to "redirect requests to this destination" and type in "http://www.domain1.com"

I also check the box that says "Redirect all requess to exact destination (instead of relative to destination)

Finally i change the status code to "Permanent (301)"

I apply all the settings and when i go to my browser and type "domain1.com" after a few seconds i get an "Internet Explorer cannot display the webpage" message. The address in the address bar changes to http://localhost

As a test, i setup the redirect to go to "http://www.google.com" with the same settings and went to my browser and typed "domain1.com" and the page was redirected to google.

What am i missing and what do i need to do so when someone internally types "domain1.com" in their browser it will take them to our externally hosted website.

Thanks,
Avatar of dinkytoy101
dinkytoy101
Flag of United Kingdom of Great Britain and Northern Ireland image

In your DNS manager a additional A record will be required to handle domain1.com as well as your already created www.domain1.com. Unless you have the site configured with host headers then the redirect really isn't required.
This solution worked for me:

1) Install URL Rewrite component:

http://www.iis.net/download/urlrewrite

2) Add to web.config:

<system.webServer>
 <rewrite>
  <rules>
   <rule name="CanonicalHostNameRule1" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
     <add input="{HTTP_HOST}" pattern="^mysite\.com$" />
    </conditions>
    <action type="Redirect" url="http://www.mysite.com/{R:1}" />
   </rule>
  </rules>
 </rewrite>
</system.webServer>

Open in new window

Avatar of jkpc21
jkpc21

ASKER

When I add that code to the web.config i get an "HTTP Error 500.19 - Internal Server Error" when i try browsing to the website.

Can you point out what text on that code exactly i need to replace with the URL i am looking to redirect to. Can you do this by substituting the text to "http://www.domain1.com

Thanks,
Try this code:
<rewrite>
   <rules>
      <rule name="non www to www" enabled="true">
         <match url="(.*)" />
         <conditions>
            <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
         </conditions>
         <action type="Redirect" url="<a href="http://www.{HTTP_HOST}/{R:0"
>http://www.{HTTP_HOST}/{R:0</a>}" appendQueryString="true" redirectType="Permanent" />
      </rule>
   </rules>
</rewrite>

Open in new window

Avatar of jkpc21

ASKER

I've attached a screenshot of the error i get when trying to access the page after entering in the new code.
 User generated image
ASKER CERTIFIED SOLUTION
Avatar of jkpc21
jkpc21

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jkpc21

ASKER

The issue actually had to do with something on our outside web server. When someone would go to our site, the www would get dropped and therefore regardless of what we put in IIS as soon as the www got dropped the server saw in can be resolved internally and therefor took us to the IIS page. We notified our web host and they made changes to the web server so it does not drop the www. This resolved the issue.