IIS Rewrite rule doesn't work

Chris du Preez 20 Reputation points
2023-11-16T07:36:33.3933333+00:00

Good day,

I have a website developed in WordPress, it has a subsite, the mains sites URL is https://wp-test.flamengro.co.za the subsite is https://wp-test.flamengro.co.za/imt I want to redirect https://imt.flamengro.co.za to https://wp-test.flamengro.co.za/imt. https://wp-tes.flamengro.co.za and https://imt.flamengro.co.za have the same ip address. I have tried the two below examples but https://imt.flamengro.co.za loads the main site. The OS is Windows Server 2019 with iis server 10.0.17763.1.

				<rule name="IMT Path to Another Domain" stopProcessing="true">
					<match url=".*" />
					<conditions>
						<add input="{HTTP_HOST}" pattern="imt.flamengro.co.za" />
						<add input="{PATH_INFO}" pattern="/(Path1).*" negate="true" />
					</conditions>
					<action type="Rewrite" url="https://wp-test.flamengro.co.za/imt" />
				</rule>
				<rule name="imt" stopProcessing="true">
                    <match url="^(www.)?(imt).flamengro.co.za$" />
                    <conditions trackAllCaptures="true">
                        <add input="{HTTP_HOST}" pattern="^(www.)?(imt).flamengro.co.za$" />
                    </conditions>
                    <action type="Rewrite" url="https://wp-test.flamengro.co.za/{R:2}" />
                </rule>
Windows development Internet Information Services
Windows for business Windows Server User experience Other
{count} votes

Accepted answer
  1. Yurong Dai-MSFT 2,846 Reputation points Microsoft External Staff
    2023-11-20T03:28:15.0533333+00:00

    Hi @Chris du Preez,
    You just use the following redirect rule:

                    <rule name="redirect" enabled="true" stopProcessing="true">
                        <match url=".*" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="imt.flamengro.co.za" />
                        </conditions>
                        <action type="Redirect" url="https://wp-test.flamengro.co.za/imt" />
                    </rule>
    

    I have tested this rule and can successfully redirect https://imt.flamengro.co.za to https://wp-test.flamengro.co.za/imt.

    It is recommended that you clear your browser cache before testing. If you still can't succeed, try using FRT to trace the rewrite rules, you can see how the rules are used internally.

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

    If you have any questions, please continue to communicate with me and I will get back to you as soon as I see it.


    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

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.