How to redirect or rewrite IIS site with port in URL to URL without port?

22,334

Try This

<configuration>
<system.webServer>
    <rewrite>
           <rules>
            <rule name="removePort" stopProcessing="true">
                <match url="^(http(s)?://)?(portal\.company\.com):7500(/.*)?$" />
                <action type="Redirect" url="https://{R:3}/{R:4}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

Share:
22,334

Related videos on Youtube

user2573690
Author by

user2573690

Updated on September 18, 2022

Comments

  • user2573690
    user2573690 over 1 year

    I'm not 100% sure if this is the right part of StackOverflow to post this but to me it made the most sense. Sorry if its not!

    Currently I have a site in IIS configured on HTTPS with port 7500. I can access this site by using the URL: https://portal.company.com:7500.

    What I would like to do is remove the port number at the end of the URL so users can access this site using https://portal.company.com...

    I am a complete beginner with IIS, but what I have tried is the HTTP Redirect, which if I used on this IIS site, would redirect a user that hits portal.company.com:7500 to some other site, which is not what I need. Another thing I have though about is creating another IIS site which serves the purpose of being at the URL portal.company.com and when its hit, it redirects to my portal.company.com:7500, but I don't know if this is the best approach.

    So my question is, what are my options for achieving the behavior mentioned above and what is the best/recommended approach?

    I haven't played with URL Rewriting before but I will look into that now while I wait for a reply. Thanks!!

    Using IIS Manager on a Windows Server 2008 machine.

  • user2573690
    user2573690 over 10 years
    Thanks for the answer. Well the site is actually HTTPS and I have another site running on port 443, and it looks like the default site is running on 444. Any other ideas?
  • Lee Harrison
    Lee Harrison over 10 years
    URL Rewrite can be used to redirect to a different port fairly easily, and would be the route I'd recommend here. The following tutorial is for exchange but it can be adapted to what you're doing. morgansimonsen.wordpress.com/2009/04/02/…
  • phoebus
    phoebus over 10 years
    Rewriting involves redirecting the user at the HTTP layer, it won't allow them to host two SSL sites on the same IP.
  • Lee Harrison
    Lee Harrison over 10 years
    The is nothing stopping you from running two HTTPS sites on the same IP. See a Lync Frontend server, it setup that way by default. The same PORT, yes that wouldn't work. Your down vote is unwarranted. URL Rewrite can be used to redirect port 80 traffic over to port 7500, don't listen to phoebus. Just make sure your certificates are right.
  • user2573690
    user2573690 over 10 years
    Thanks for the answer. Yes I am trying to have users access the portal.domain.com without any port number. Also I do have a wildcard certificate for *.domain.com so I will try running through the procedure you posted.
  • user2573690
    user2573690 over 10 years
    I tried the procedure you mentioned and set both of my sites to port 443 and ran the command in cmd but it did not work, when I try to start my second site I get the port is already in use error message...any ideas
  • TomTom
    TomTom over 9 years
    @LeeHarrison "The is nothing stopping you from running two HTTPS sites on the same IP" - except that single idiotig ting called reality. Unless you use a very modern OS (2008 is not) the host header is in the encrypted part of the payload. How do the two programs negotiate on such an outdated OS which one gets the connection without knowing which one is the target. Wildcards work, as does a more modern operating system.
  • HBruijn
    HBruijn about 9 years
    That's not actually the case, with Server Name Indication (SNI) you can have multiple certificates on the same IP address and TCP port number.