IIS 7 Http Redirect Issues

jkpc21
jkpc21 used Ask the Experts™
on
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,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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.

Commented:
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

Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Author

Commented:
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,

Commented:
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

Author

Commented:
I've attached a screenshot of the error i get when trying to access the page after entering in the new code.
 Error
Commented:
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.

Author

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial