rewrite only 1 single page RSS

8 replies

Last post Feb 20, 2020 07:11 PM by Rovastar

  • rewrite only 1 single page

    Feb 11, 2020 06:24 PM|tdemeyer|LINK

    Hi,

    IIS10 + url rewite and arr installed here. This system is used as reverse proxy for several sites (exposing entire internal websites to the internet, nothing fancy)

    I have a special situation now: We need to expose 1 single local webpage to the internet, any other external url must be dropped or generate an error/page not found.

    So : https://external.domain.com/ needs to point to http://internal.domain/local/page.php

    but https://external.domain.com/index.php, or ../page.php  (anything after the fqdn) must be blocked

    the internal page (http://internal.domain/local/page.php) contains references to (images/content/..) to other elements on the same site.

    any help on this is most welcome

    Tim

  • Re: rewrite only 1 single page

    Feb 12, 2020 02:14 AM|Jalpa Panchal|LINK

    Hi,

    You could try to use a match pattern like below in rule:

     <rule name="ReverseProxyInboundRule5" enabled="true" stopProcessing="true">
                        <match url="^$" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="external.domain.com" />
                            <add input="{HTTPS}" pattern="on" />
                        </conditions>
                        <action type="Rewrite" url="http://internal.domain/local/page.php" logRewrittenUrl="true" />
                    </rule>

    ^$ only math the domain name after that all the requested URL will not allow tp to rewrite the URL.

    Note: the above mentioned rule is just an example you could modify rule based on your requirement.

    Regards,

    Jalpa

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: rewrite only 1 single page

    Feb 12, 2020 07:29 AM|tdemeyer|LINK

    I was  getting a 500 internal server error... After I removed my 'default'outbound rewrite rules, the page displays, but any graphis etc are missing. 

    So I'm half-way :)

     

  • Re: rewrite only 1 single page

    Feb 13, 2020 01:23 AM|Jalpa Panchal|LINK

    Could you please share your web.config file and the browser snapshot?

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: rewrite only 1 single page

    Feb 13, 2020 07:58 AM|tdemeyer|LINK

    OK, here we go :)

    First: this is what the page should normally look:

    https://imgur.com/KoWKvuX

    This is how it looks without any outbound rule defined

    https://imgur.com/MW8rsbG

    And with my default outbound rules (as in: used on 10 other sites)

    https://imgur.com/V8z6lLO

    And this is the complete rule that goes with the above error 500

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    	<system.webServer>
    		<rewrite>
    			<rules>
    				<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
                        <match url="^$" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="external.domain.com" />
                            <add input="{HTTPS}" pattern="on" />
                        </conditions>
                        <action type="Rewrite" url="http://internal.domain.local/page.php" logRewrittenUrl="true" />
                    </rule>
    			</rules>
    			<outboundRules>
    				<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
    					<match filterByTags="A, Form, Img" pattern="^http(s)?://internal.domain.local/(.*)" />
    					<action type="Rewrite" value="https://external.domain.com/{R:2}" />
    				</rule>
    				<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
    					<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" />
    					<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" />
    				</rule>
    				<rule name="Deal with href tags" preCondition="ResponseIsHtml1">
    					<match filterByTags="None" pattern="href=(.*?)http://internal.domain.local/(.*?)\s" />
    					<action type="Rewrite" value="href={R:1}https://external.domain.com/{R:2}" />
    				</rule>
    				<rule name="Deal with action tags" preCondition="ResponseIsHtml1">
    					<match filterByTags="None" pattern="action=(.*?)http://internal.domain.local/(.*?)\\" />
    					<action type="Rewrite" value="action={R:1}https://external.domain.com/{R:2}\" />
    				</rule>
    				<preConditions>
    					<preCondition name="ResponseIsHtml1">
    						<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/(.+)" />
    					</preCondition>
    					<preCondition name="NeedsRestoringAcceptEncoding">
    						<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
    					</preCondition>
    				</preConditions>
    			</outboundRules>
    		</rewrite>
    	</system.webServer>
    </configuration>

  • Re: rewrite only 1 single page

    Feb 13, 2020 08:25 AM|Jalpa Panchal|LINK

    Could you please share what is the old rule? Generate Failed request tracing and get the detail where you failed. Generally, this error occurred when did not find the requested content.

    You should be able to see the rewritten rule in the trace, try accessing the URL directly to see if you get the 500.

    Also, check the IIS logs on both the IIS and ARR servers to see on which one the 500 is happening.

    https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue.
    If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
  • Re: rewrite only 1 single page

    Feb 13, 2020 10:04 AM|tdemeyer|LINK

    I have no old rule. This is a new setup. I just copied a web.config from one of our active sites, and started bij replacing the inbound rule with the one that was published here (of course: making sure internal and external URL's are correct)

    When using only the inbound rule, and no outbound: the site displays obviously (?) without any refereced images etc.. (as the internal localtion is not translated)

    When using inbound + outbound rules there's the 500 error

    The internal site is accessible from the 'rewrite server' without any error.

    Will try to get some logs (I have limited access to the machine)

  • Re: rewrite only 1 single page

    Feb 20, 2020 03:37 PM|tdemeyer|LINK

    bump.. Nobody that can help me on this?

  • Rovastar Rovastar

    5445 Posts

    MVP

    Moderator

    Re: rewrite only 1 single page

    Feb 20, 2020 07:11 PM|Rovastar|LINK

    I'll bump back. Failed request tracing will tell you step by step which bits failed and why.
    Troubleshoot IIS in style
    https://www.leansentry.com/