Redirect to another site but show the original URL in browser

FelipeSantosBRA 61 Reputation points
2024-02-26T16:35:12.98+00:00

Hi.

I need help with a question about URL Rewrite.

Currently the redirection rule below works correctly.

<rule name="test_redirect" stopProcessing="true">
    <match url="^(.*)$" />
	    <conditions>
		    <add input="{HTTP_HOST}" pattern="^name.domain.com$" />
            <add input="{HTTPS_HOST}" pattern="^name.domain.com$" />
	    </conditions>
    <action type="Redirect" url="http://IP address/service" redirectType="Permanent" />
</rule>

Now what I need is that the browser's address bar still displays the original url.

Example: "http://name.domain.com" redirects to "http://IP address/service" but the browser's address bar still displays "http://name.domain.com".

Can anyone help me with this?

Thanks.

Windows development | Internet Information Services
{count} votes

1 answer

Sort by: Most helpful
  1. Yurong Dai-MSFT 2,846 Reputation points Microsoft External Staff
    2024-02-27T04:38:45.8233333+00:00

    Hi @FelipeSantosBRA,

    To achieve a redirection where the browser's address bar still displays the original URL while redirecting internally to another URL, you need to use a reverse proxy setup instead of a HTTP redirection.

    Firstly, you need to install the ARR module, download link: https://www.iis.net/downloads/microsoft/application-request-routing

    After the installation is complete, you can see the ARR module at the IIS server level. Double-click to open it, select Server Proxy Settings, and check Enable proxy.

    User's image Then set the rewrite rules in the site, here's how you can achieve this with URL Rewrite:

    <rule name="test_reverse_proxy" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^name.domain.com$" />
            <add input="{HTTPS_HOST}" pattern="^name.domain.com$" />
        </conditions>
        <action type="Rewrite" url="http://IP address/service/" />
    </rule>
    

    This rule will internally rewrite requests from http://name.domain.com to http://IP address/service, but the browser's address bar will still display http://name.domain.com. For more information about IIS reverse proxy, please refer to the following documents: Setup IIS with URL Rewrite as a reverse proxy for real world apps Reverse Proxy with URL Rewrite v2 and Application Request Routing


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the email notification for this thread. Best regards, Yurong Dai


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.