0

I am running the Wordpress multisites on IIS 10 (Windows server). I have 3 sites like that.

<rewrite>
    <rules>
        <rule name="WordPress Rule 1" enabled="true" stopProcessing="true">
            <match url="^index\.php$" ignoreCase="false" />
            <action type="None" />
        </rule>
        <rule name="WordPress Rule 2" stopProcessing="true">
            <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" />
            <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" />
        </rule>
        <rule name="WordPress Rule 3" stopProcessing="true">
            <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
            <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
        </rule>
        <rule name="WordPress Rule 4" stopProcessing="true">
            <match url="^" ignoreCase="false" />
            <conditions logicalGrouping="MatchAny">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
            </conditions>
            <action type="None" />
        </rule>
        <rule name="WordPress Rule 5" stopProcessing="true">
            <match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
            <action type="Rewrite" url="{R:2}" />
        </rule>
        <rule name="WordPress Rule 6" stopProcessing="true">
            <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
            <action type="Rewrite" url="{R:2}" />
        </rule>
        <rule name="WordPress Rule 7" enabled="true" stopProcessing="true">
            <match url="." ignoreCase="false" />
            <action type="Rewrite" url="index.php" />
        </rule>
    </rules>
</rewrite>

It works.

I don't really need the main site so I changed the main site to be 2 (https://test.mydomain.com/subsite1)

When the user accesses the website https://test.mydomain.com or https://test.mydomain.com/, I want to redirect to https://test.mydomain.com/subsite1.

In summary, I want to work like that.

I have tried this IIS rewrite rules but didn't work.

<rule name="Main To Subsite" enabled="true" stopProcessing="true">
    <match url="^https:\/\/test.mydomain.com$" ignoreCase="false" />
    <action type="Redirect" url="subsite1/" redirectType="Temporary" logRewrittenUrl="true" />
</rule>
<rule name="Main To Subsite /" enabled="true" stopProcessing="true">
    <match url="^http:\/\/test.mydomain.com\/$" ignoreCase="false" />
    <action type="Redirect" url="subsite1/" redirectType="Temporary" logRewrittenUrl="true" />
</rule>

I could probably use some regular expressions like lookahead and etc. I am not that familiar with IIS rewrite. I've read up but still not working. Any help would be appreicated.

Edited: I found this https://www.createit.com/blog/multisite-redirect-from-main-site/ but it is done in functions.php. I think that we should be able to do it from IIS rewrite.

ThomasArdal
  • 4,999
  • 4
  • 33
  • 73
Michael Sync
  • 4,834
  • 10
  • 40
  • 58

1 Answers1

0

enter image description here

Thanks all. I found the answer here https://stackoverflow.com/a/35759141

<rule name="Root Redirect" stopProcessing="true">
    <match url="^$" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
    <action type="Redirect" url="en/" redirectType="Permanent" />
</rule>
ThomasArdal
  • 4,999
  • 4
  • 33
  • 73
Michael Sync
  • 4,834
  • 10
  • 40
  • 58
  • People tend to close duplicate questions, instead of posting new answers, but you can feel free to accept your own answer. – Lex Li Jan 19 '23 at 16:38