Make WordPress Core

Opened 11 years ago

Last modified 5 years ago

#25106 new defect (bug)

web.config for multisite configurations on IIS7

Reported by: mrevets's profile mrevets Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5
Component: Rewrite Rules Keywords: needs-patch needs-unit-tests
Focuses: multisite Cc:

Description

The code that WordPress gives me for the web.config is incorrect. I downloaded the new 3.6 and this issue happened. I found the issue and solved it but wanted to let you know of this error as not many people run multisites on IIS7. So the rewrite code that was the issues is the following and was Rule 2

<rule name="WordPress Rule 2" stopProcessing="true">
  <match url="^wp-admin$" ignoreCase="false" />
  <action type="Redirect" url="wp-admin/" redirectType="Permanent" />
</rule>

what i can tell this is trying to do is if a user types in just "domain.com/wp-admin" that it would redirect them to "domain.com/wp-admin/" but the desired results did not happen. the above code would redirect you to "domain.com/domain.com/wp-admin/" which obviously would cause issues after the user logs in as the redirect_to would point to http://domain.com./domain.com/wp-admin/ which would cause an endless loop. To fix this problem you need to add a / to the beginning of the rewrite like so

<rule name="WordPress Rule 2" stopProcessing="true">
    <match url="^wp-admin$" ignoreCase="false" />
    <action type="Redirect" url="/wp-admin/" redirectType="Permanent" />
</rule>

that extra / before the wp-admin/ forces it to the root of the site.. now i am not sure what this would do to a site in a sub directory but im not in a sub directory so not an issue for me.

Attachments (2)

25106.patch (624 bytes) - added by SergeyBiryukov 11 years ago.
25106.2.diff (639 bytes) - added by nacin 11 years ago.

Download all attachments as: .zip

Change History (21)

#1 @SergeyBiryukov
11 years ago

  • Component changed from General to IIS

Related: #23748, #24963

#2 @SergeyBiryukov
11 years ago

  • Version changed from 3.6 to 3.5

Appears to be introduced in [22042]. Before 3.5, subdomain installs didn't have that rewrite rule.

#3 @mrevets
11 years ago

I have never used multi sites till yesterday. So the only code I have tested is 3.6

#4 @SergeyBiryukov
11 years ago

  • Keywords has-patch added

25106.patch (untested) uses $iis_rewrite_base instead of an empty string in network_step2().

#5 @SergeyBiryukov
11 years ago

  • Milestone changed from Awaiting Review to 3.7

@nacin
11 years ago

#6 @nacin
11 years ago

It looks like it is possible that $iis_rewrite_base is empty — It is based on $rewrite_base which could be reduced to an empty string as well. If the goal is to have a slash there, I don't think this is it. Unless I'm mistaken, Apache doesn't use slashes at the start of the second piece of a rewrite rule — I guess IIS does?

mrevets, we're happy to fix this but we need some feedback from you as to whether this patch works. Can you also try 25106.2.diff?

#7 @mrevets
11 years ago

Yes I can try this change and let you know what happens. But just to give you more background, this is also happening on my single WP sites. I would go to /wp-admin and I would get the double reference in the redirect_to. I had to create a custom rewrite rule to handle this case..

To give you some more information about this. I am hosted on GoDaddy using their unlimited plan. So I have one site that has to point to the root of the site but there are no real sites hosted from it that primary domain. Inside that root folder I create domain1.com, domain2.com, domain3.com and point host headers to those folders. So to the site they believe that their root is root\domain1.com

So for example i have

Root <- main.nu points to here

  • mozhabong.com <- Mozhabong.com points to here
  • bbref.ca <- bbref.ca points to here
  • caspan.com <- caspan.com points to here

and so on..

I am going to try an experiment and add a folder called xxx and add WordPress to it using one of my spare domains and see if the redirect says /xxx/domain.com or if it says /domain.com/domain.com because it is hard to tell if its the folder name its duplicating because that is the name of the folder it is in or if its just putting the domain name in their twice. I will setup and test right away to let you know..

Then I will also test the changes you have asked me to make on this test site.

#8 @nacin
11 years ago

  • Milestone changed from 3.7 to 3.8

Moving to 3.8 pending testing and feedback.

#9 @mrevets
11 years ago

okay just did some testing. I took my domain, mrevets.com and set it up at godaddy to point to a folder called "test" off the root site. I then setup WP and database and took the wp-admin/index.php and added a phpinfo() and exit right away. If you go to "http://mrevets.com/wp-admin" you should see my PHP Info dump and if you look at the URL you will see it has /test/wp-admin... but if you hit http://mrevets.com/wp-admin/ then it shows /wp-admin/ in the URL at the top.

so you can see that "_SERVERREQUEST_URI?" is different depending on if you add a / or not, very strange jsut by adding a / to the end that it would change this variable.. I am thinking it has to do with the rewrite..

Not sure if this helps but i will leave the site up like this for you to see and then I will try the change you mentioned...

Let me know when I can try your change..

#10 @mrevets
11 years ago

Sorry so this above shows that it's not trying to hit the domain twice in the url but adding the parent folder name when you leave off the / . I could not tell before because all my folder names were the same as the domain names.

#11 @netweb
11 years ago

I cannot reproduce this using WordPress r25761

NOTE: This test is NOT using WordPress MU Domain Mapping plugin.

Setup x64 Windows 8.1, IIS 8.5, IIS URL Rewrite Module 2 v7.2.2

Primary site: http://primarysite.nw/wp-admin/
Sub Domain Site 1: http://firstsite.primarysite.nw/
Sub Domain Site 2: http://secondsite.primarysite.nw/

All three sites using Post name permalinks /%postname%/ eg. http://primarysite.nw/sample-post/

/wp-admin <- All sites work 'as expected'

Hello World <- All sites work 'as expected'

wp-config.php (excerpt only)

/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'primarysite.nw');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="WordPress Rule 1" stopProcessing="true">
                    <match url="^index\.php$" ignoreCase="false" />
                    <action type="None" />
                </rule>
                <rule name="WordPress Rule 2" stopProcessing="true">
                    <match url="^wp-admin$" ignoreCase="false" />
                    <action type="Redirect" url="wp-admin/" redirectType="Permanent" />
                </rule>
                <rule name="WordPress Rule 3" 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 4" stopProcessing="true">
                    <match url="^(wp-(content|admin|includes).*)" ignoreCase="false" />
                    <action type="Rewrite" url="{R:1}" />
                </rule>
                <rule name="WordPress Rule 5" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>
                <rule name="WordPress Rule 6" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

#12 @netweb
11 years ago

The following are the results INCLUDE WordPress MU Domain Mapping plugin.

Primary site: http://primarysite.nw/wp-admin/
Sub Domain Site 1: http://firstsite.primarysite.nw/
Sub Domain Site 2: http://secondsite.primarysite.nw/

All three sites using Post name permalinks /%postname%/ eg. http://primarysite.nw/sample-post/

CASE 1: MU Domain Mapping using 'Primary Key' = YES
(http://primarysite.nw/wp-admin/network/settings.php?page=dm_domains_admin')

EDIT: Via /network/settings.php?page=dm_admin_page the following 'deafult out of the box' options were used:

  • 1 YES Remote Login
  • 2 NO Permanent redirect (better for your blogger's pagerank)
  • 3 YES User domain mapping page
  • 4 YES Redirect administration pages to site's original domain (remote login disabled if this redirect is disabled)
  • 5 NO Disable primary domain check. Sites will not redirect to one domain name. May cause duplicate content issues.
Site ID Domain Primary
2 firstsite.nw Yes
3 secondsite.nw Yes

/wp-admin

CASE 2: MU Domain Mapping using 'Primary Key' = NO

Site ID Domain Primary
2 firstsite.nw No
3 secondsite.nw No

With the sites primary key set to 'No' all URL's will be as per results in previous comment #11

Hello World <- All sites work 'as expected'

wp-config.php (excerpt only)

/* Multisite */
define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'primarysite.nw');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/');

/* Include WordPress MU Domain Mapping config. */
define( 'SUNRISE', 'on' );

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
Last edited 11 years ago by netweb (previous) (diff)

#13 @netweb
11 years ago

CASE 3: MU Domain Mapping using 'Primary Key' = YES
(http://primarysite.nw/wp-admin/network/settings.php?page=dm_domains_admin')

Via /network/settings.php?page=dm_admin_page the following options were used:

  • 1 YES Remote Login
  • 2 NO Permanent redirect (better for your blogger's pagerank)
  • 3 YES User domain mapping page
  • 4 NO Redirect administration pages to site's original domain (remote login disabled if this redirect is disabled)
  • 5 NO Disable primary domain check. Sites will not redirect to one domain name. May cause duplicate content issues.
Site ID Domain Primary
2 firstsite.nw Yes
3 secondsite.nw Yes

/wp-admin

#14 @netweb
11 years ago

CASE 4: MU Domain Mapping using 'Primary Key' = YES
(http://primarysite.nw/wp-admin/network/settings.php?page=dm_domains_admin')

Via /network/settings.php?page=dm_admin_page the following options were used :

  • 1 NO Remote Login
  • 2 NO Permanent redirect (better for your blogger's pagerank)
  • 3 YES User domain mapping page
  • 4 NO Redirect administration pages to site's original domain (remote login disabled if this redirect is disabled)
  • 5 YES Disable primary domain check. Sites will not redirect to one domain name. May cause duplicate content issues.
Site ID Domain Primary
2 firstsite.nw Yes
3 secondsite.nw Yes

/wp-admin <- All sites work 'as expected'

#15 @netweb
11 years ago

  • Cc netweb added

#16 follow-up: @nacin
11 years ago

  • Keywords needs-patch added; has-patch needs-testing dev-feedback removed
  • Milestone changed from 3.8 to Future Release

Still does not appear to be a final patch here. I'm happy to fix whatever but I still don't know what's going on here, and multisite rewrites are a bear.

#17 in reply to: ↑ 16 @netweb
11 years ago

  • Keywords needs-unit-tests added

Replying to nacin:

Still does not appear to be a final patch here. I'm happy to fix whatever but I still don't know what's going on here, and multisite rewrites are a bear.

Agreed.

From my tests above some unit tests for multisite around /wp-admin links for both sub-directory and sub-domain mutisite setups would also future proof this issue reoccurring.

#18 @nacin
11 years ago

  • Component changed from IIS to Rewrite Rules
  • Focuses multisite added

This ticket was mentioned in Slack in #docs by netweb. View the logs.


9 years ago

Note: See TracTickets for help on using tickets.