We help IT Professionals succeed at work.

How do I forward a URL to a sub-page in IIS

I am running a Windows 2008 server with IIS 7.0. I need to forward a URL/Domain to a specific page within our new site. For example department.oldsite.com needs to point to www.newsite.com/department.

Also for internal reasons I don't want to maintain a site or any pages for oldsite.com. Is there a setting within IIS that will allow me to do this? I've looked into 301 re-directs, domain aliases and even virtual webs, but I am not sure which is the right tool for the job?
Comment
Watch Question

Tray896SharePoint Engineer

Commented:
The absolute easiest way of doing this would be to just create a new page within department.oldsite.com named something like redirect.htm.  Edit this new page, and paste the following:

<meta http-equiv="refresh" content="0;url=http://www.newsite.com/department"/>

Save the page, and within IIS set redirect.htm as the default document for the department.oldsite.com .  Now when users hit department.oldsite.com, they'll be immediately redirected to www.newsite.com/department.

If you are dead site on not leaving a website running for the old site, then an alternative option may be to use the URL Rewrite Module for IIS 7.  You can read more about how to use and install it here: http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
Brad HoweDevOps Manager
Top Expert 2011

Commented:
Hi,
Yes, the proper way would be to use the new URL rewrite feature.

Here is where to get the module:
Download the x86 version for IIS 7.0 (http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1691)
Download the x64 version for IIS 7.0 (http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1692)

Once you have installed the module, you can simply copy and paste the following code between the <rules> and </rules> tags in your your web.config file in your website root directory. To simplify this for you, I have created the following rule for you.

       <rewrite>
            <rules>
                <rule name="Domain to domain/virtual directory" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^www.newsite.com$" />
                    </conditions>
                    <action type="Redirect" url="http://www.newsite.com/department" redirectType="Permanent" />
                </rule>


           </rules>
       </rewrite>

If you want help creating import masks, please provide a list of all the sample URLS and there supposed redirects and we would be glad to help create an import_rules file for you.

Here is a great article on how to create 301 redirect rules.
http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/
 
Cheers,
Hades666
Hi,

Create the sub-domain department.oldsite.com in IIS after that create the IIS redirect to www.newsite.com/department, It is very easy way to do it.
Brad HoweDevOps Manager
Top Expert 2011

Commented:
@sethisaurabh - He is using IIS7. The process just clutters your mgmt console with virtual sites. I would use rthe url rewrite to achieve the same results. It free and simple to configure. Plus I provided the working rule.
Try it.

Cheers,
Hades666
Hi hades666

You are right that IIS7 Url rewrite will work but he has to create the sub-domain department.oldsite.com in that case also. Creating the IIS redirecting is very easy instead of web.config rewrite rule that's why I suggested this.
Brad HoweDevOps Manager
Top Expert 2011

Commented:
He already has the subdomain. "For example department.oldsite.com needs to point to www.newsite.com/department. "

1)
Add 2 bindings to your "Web Site"
1. Go to IIS Manager
2. Select your “Web Site” on the left pane.
3. In the "Actions" pane on right hand side, click on "Bindings..."
4. Click ADD.
  * You should have 2 or more bindings depending on your urls.
    a) Type (http) - host Name (newsite.com) -  Port (80) - IP address (*)
    b) Type (http) - host Name (department.oldsite.com ) -  Port (80) - IP address (*)

2) Install the rewrite module.

3) Add the web.config rule
            <rules>
                <rule name="Domain to domain/virtual directory" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^www.newsite.com$" />
                    </conditions>
                    <action type="Redirect" url="http://www.newsite.com/department" redirectType="Permanent" />
                </rule>
           </rules>

No site required.

-Hades666

Author

Commented:
We installed the rewrite module for IIS and followed instructions, but have not had any luck getting it to work yet. We are still getting the IIS7 default page.  I'm wondering if we need a host header on the default site for department.oldsite.com. Is that what you meant by "Bindings"?
Brad HoweDevOps Manager
Top Expert 2011

Commented:
yes, Exactly.  The site that is newsite.com needs a binding for department.oldsite.com. - Hades666

Author

Commented:
We set up the bindings as you describe above but we are still getting the IIS7 default page? Any other ideas?
DevOps Manager
Top Expert 2011
Commented:
Hi,

The rule was incorrect. the HTTP_HOST should be department.oldsite.com not newsite. Here is a correct setup. You can past this into the Home Directory web.config OR follow the screenshot below.

          <rules>
                <rule name="Domain to domain/virtual directory" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^department.oldsite.com$" />
                    </conditions>
                    <action type="Redirect" url="http://www.newsite.com/department" redirectType="Permanent" />
                </rule>
           </rules>

If you type (www)?newsite.com  you will get the default page. If you type department.oldsite.com you get www.newsite.com/department.

Let me know if you have any issues,
Hades666
ee1.jpg
ee2.jpg
ee3.jpg

Author

Commented:
Excellent!