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.
- https://test.mydomain.com [redirect to ] https://test.mydomain.com/subsite1
- https://test.mydomain.com/ [redirect to ] https://test.mydomain.com/subsite1
- https://test.mydomain.com/wp-admin or wp-login or anything [it should work as it's. It shouldn't redirect to subsite.]
- https://test.mydomain.com/subsite1 [it should work as it is]
- https://test.mydomain.com/subsite1/wp-admin [it should work as it is]
- https://test.mydomain.com/subsite2/ [it should work as it is]
- https://test.mydomain.com/subsite2/wp-admin [it should work as it is]
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.