Opened 9 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 | Owned by: | 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 )
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)
Change History (26)
#2
@
9 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.
#4
@
9 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.
#5
follow-up:
↓ 6
@
9 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
@
9 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
andWordPress
?
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 :)
#7
follow-up:
↓ 11
@
9 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.
#8
@
9 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.
9 years ago
#11
in reply to:
↑ 7
@
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
@
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:
↓ 16
↓ 18
@
8 years ago
@webshaun Are you able to test the latest patch on your install? That would be great!
#14
@
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.
#16
in reply to:
↑ 13
@
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
@
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.
Hello @oneumyvakin, welcome to Trac!
Thanks fro
Could this be caused by [36953] somehow?