Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#36506 closed defect (bug) (fixed)

Duplicate directives in web.config after WordPress 4.5 installation on Windows

Reported by: oneumyvakin's profile oneumyvakin Owned by: swissspidy's profile swissspidy
Milestone: 4.5.1 Priority: normal
Severity: normal Version: 4.5
Component: Rewrite Rules Keywords: has-patch commit fixed-major
Focuses: Cc:

Description (last modified by ocean90)

DESCRIPTION
Duplicate directives in web.config after WordPress 4.5 installation on Windows

ENVIRONMENT

  • WordPress 4.5
  • Windows 2012 R2
  • PHP 5.4.45

IMPACT

  • WordPress can't be used

STEPS
# Extract wordpress-4.5.zip archive into domain's root or sub-folder
# Start installation procedure
# Installation wizard finished without any error
# Try to open login page or home page

ACTUAL RESULT
Error 500

EXPECTED RESULT

  • No such error

ROOT CAUSE

IIS error:

\\?\<path>\httpdocs\wordpress\web.config ( 6) :Cannot add duplicate collection entry of type 'rule' with unique key attribute 'name' set to 'WordPress: http://test.plesk.ru/wordpress' 

Content of web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules><rule name="WordPress: http://test3.a10-52-58-17.qa.plesk.ru" patternSyntax="Wildcard"><match url="*"/><conditions><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/></conditions><action type="Rewrite" url="index.php"/></rule>

			<rule name="WordPress: http://test3.a10-52-58-17.qa.plesk.ru" patternSyntax="Wildcard">
				<match url="*"/>
					<conditions>
						<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
						<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
					</conditions>
				<action type="Rewrite" url="index.php"/>
			</rule></rules>
    </rewrite>
  </system.webServer>
</configuration>

Attachments (5)

misc.diff (925 bytes) - added by WiZZarD_ 8 years ago.
misc.2.diff (943 bytes) - added by WiZZarD_ 8 years ago.
misc.php.patch (1.1 KB) - added by WiZZarD_ 8 years ago.
misc.php.2.patch (1.9 KB) - added by WiZZarD_ 8 years ago.
misc.php.3.patch (1.7 KB) - added by WiZZarD_ 8 years ago.

Download all attachments as: .zip

Change History (26)

#1 @ocean90
8 years ago

  • Component changed from General to Rewrite Rules
  • Description modified (diff)

Hello @oneumyvakin, welcome to Trac!

Thanks fro

Could this be caused by [36953] somehow?

#2 @WiZZarD_
8 years ago

Nope. I've tested it with a rollback for that specific change and it still happens. I'm investigating already. Can confirm this behavior.
Edit:
Actually, that fix did break it. Before writing the new rules, WP will check to see if there are already rules in place. It does that by searching for the 'old' rule name: wordpress. Not the new and updated one. So each time you save your permalink settings, a new entry will be made.

Last edited 8 years ago by WiZZarD_ (previous) (diff)

@WiZZarD_
8 years ago

#3 @WiZZarD_
8 years ago

Attached diff for /wp-admin/includes/misc.php should fix this.

Last edited 8 years ago by WiZZarD_ (previous) (diff)

#4 @ocean90
8 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.5.1

Thanks @WiZZarD_, nice catch! You're patch is missing the file references, it's only ".php". Can you try it again please? See also https://make.wordpress.org/core/handbook/tutorials/trac/submitting-a-patch/ for help.

@WiZZarD_
8 years ago

@WiZZarD_
8 years ago

#5 follow-up: @ocean90
8 years ago

misc.php.patch looks good. What happens if I have an existing install with the old rule and update to 4.5? iis7_add_rewrite_rule() wouldn't find the old rule and the new one is added as a duplicate rule with a different name?

Can we make the query case insensitive so it matches wordpress and WordPress?

#6 in reply to: ↑ 5 @JanR
8 years ago

Replying to ocean90:

misc.php.patch looks good. What happens if I have an existing install with the old rule and update to 4.5? iis7_add_rewrite_rule() wouldn't find the old rule and the new one is added as a duplicate rule with a different name?

Can we make the query case insensitive so it matches wordpress and WordPress?

Not easily, xPath 1.0 is not case sensitive, and lacks to-lower / to-upper functions like xPath 2.0 has, so you need to work around that and hack something together. Meaning a proper rewrite of the iis7_add_rewrite_rule() function.

If someone's up for the job, some more information is available at http://www.cowburn.info/2009/10/23/php-funcs-xpath/ and http://codingexplained.com/coding/php/solving-xpath-case-sensitivity-with-php

If @WiZZarD_ needs my help he knows where to find me :)

@WiZZarD_
8 years ago

#7 follow-up: @WiZZarD_
8 years ago

Existing installs should not be affected by this, as long as the permalink settings aren't updated. The first update will work, but the second update of the web.config will cause duplicate entry errors.

I've added a last patch. The check will be done case insensitive by converting all to lower case. This way the string "wordpress" (pre WP 4.5 rule name) will match as well as "WordPress" (current rule name start).

For people that are already affected and have a broken site: removing one of the duplicate entries from your web.config should fix your issues.

Last edited 8 years ago by WiZZarD_ (previous) (diff)

@WiZZarD_
8 years ago

#8 @WiZZarD_
8 years ago

Last patch is added because of DOMXPath::registerPHPFunctions() is PHP >= 5.3.0 . Changed the query to use a union operator to test for both strings (wordpress and WordPress).

This ticket was mentioned in Slack in #core by ocean90. View the logs.


8 years ago

#10 @SergeyBiryukov
8 years ago

#36544 was marked as a duplicate.

#11 in reply to: ↑ 7 @lolga
8 years ago

Replying to WiZZarD_:

For people that are already affected and have a broken site: removing one of the duplicate entries from your web.config should fix your issues.

Thank you so much! Man, I really want to hug you! I was going crazy cause of this Error 500.52 and now it works!

#12 @webshaun
8 years ago

I can confirm this is an issue. I'm running PHP 7.05 x64 on Windows Server 2012 R2.

#13 follow-ups: @swissspidy
8 years ago

@webshaun Are you able to test the latest patch on your install? That would be great!

#14 @swissspidy
8 years ago

  • Keywords commit added

Alright, I now tested this on a Windows 10 VM and can confirm both the error and the fix.

#15 @swissspidy
8 years ago

  • Owner set to swissspidy
  • Status changed from new to assigned

#16 in reply to: ↑ 13 @webshaun
8 years ago

Replying to swissspidy:

@webshaun Are you able to test the latest patch on your install? That would be great!

No, I'll have to wait for this fix to be pushed to the next public stable wordpress release.

This ticket was mentioned in Slack in #core by adamsilverstein. View the logs.


8 years ago

#18 in reply to: ↑ 13 @JanR
8 years ago

Replying to swissspidy:

@webshaun Are you able to test the latest patch on your install? That would be great!

I can confirm the issue, WordPress 4.5 on IIS 8.5 breaks upon saving permalinks. On my vanilla WP test environment, I have one rewrite rule to rewrite non-www to www:

<rewrite>
  <rules>
    <rule name="non-www to www" stopProcessing="true">
      <match url="(.*)" ignoreCase="false"/>
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^example\.com$"/>
        <add input="{URL}" pattern="(.+)" ignoreCase="false"/>
      </conditions>
      <action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent"/>
    </rule>
  </rules>
</rewrite>

When I save my Permalinks, for example to /%postname%/, the rewrite rule is saved twice. Resulting in a broken site and IIS HTTP Error 500.52 - URL Rewrite Module Error:

Cannot add duplicate collection entry of type 'rule' with unique key attribute 'name' set to 'WordPress: http://www.example.com'

Furthermore, the existing rewrite plus the first WordPress rewrite rule are placed on one line, making it hardly readable:

<rewrite>
  <rules><rule name="non-www to www" stopProcessing="true"><match url="(.*)" ignoreCase="false"/><conditions logicalGrouping="MatchAll"><add input="{HTTP_HOST}" pattern="^example\.com$"/><add input="{URL}" pattern="(.+)" ignoreCase="false"/></conditions><action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent"/></rule><rule name="WordPress: http://www.example.com" patternSyntax="Wildcard"><match url="*"/><conditions><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/></conditions><action type="Rewrite" url="index.php"/></rule>
  <rule name="WordPress: http://www.example.com" patternSyntax="Wildcard">
    <match url="*"/>
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
      </conditions>
    <action type="Rewrite" url="index.php"/>
  </rule></rules>
</rewrite>

Now, when I apply the patch misc.php.3 @WiZZarD_ created manually and remove my web.config rewrites, the result is:

  • existing rewrite rule(s) still placed on one long line
  • a working WordPress website

Web.config rewrite end result:

<rewrite>
  <rules><rule name="non-www to www" stopProcessing="true"><match url="(.*)" ignoreCase="false"/><conditions logicalGrouping="MatchAll"><add input="{HTTP_HOST}" pattern="^example\.com$"/><add input="{URL}" pattern="(.+)" ignoreCase="false"/></conditions><action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent"/></rule>
  <rule name="WordPress: http://www.example.com" patternSyntax="Wildcard">
    <match url="*"/>
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
      </conditions>
    <action type="Rewrite" url="index.php"/>
  </rule></rules>
</rewrite>

Now someone to fix function saveDomDocument() on line 626, but that's a different issue. This Permalink issue seems resolved with @WiZZarD_'s patch.

#19 @swissspidy
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 37273:

Rewrite Rules: After [36953], correctly replace existing rules on IIS when updating them.

Props WiZZarD_.
Fixes #36506 for trunk.

#20 @swissspidy
8 years ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 4.5.1

#21 @ocean90
8 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 37274:

Rewrite Rules: After [36953], correctly replace existing rules on IIS when updating them.

Merge of [37273] to the 4.5 branch.

Props WiZZarD_.
Fixes #36506.

Note: See TracTickets for help on using tickets.