Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#16076 closed defect (bug) (fixed)

web.config is remade with WPMS when changing permalinks to default issue

Reported by: frumph's profile Frumph Owned by:
Milestone: 3.1 Priority: normal
Severity: critical Version: 3.1
Component: Rewrite Rules Keywords: has-patch
Focuses: Cc:

Description

Detailed? hrm.

WordPress Multisite
Going to settings -> Permalinks, clicking on a change from a custom
permalink to the top one (no permalink structure) ?p= causes the web.config
rules to be rewritten, inside the web.config the rewrite rule wordpress -1
is not being created with the web.config, it's missing, therefor the
http://domain.tld/files/ references that can pull from the directory that
is assigned cannot pass through ms-files.php.

Another side effect, any custom rewrite rules that are in the web.config
that are made by IIS or self are removed upon the rewrite, ignoring the
name="wordpress - #" portion and just taking everything out and rewriting it
with whatever wordpress deems is necessary.

This is the web.config I currently have, pre doing anything (backed up):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
  <rule name="wordpress - 1" stopProcessing="true">
   <match url="^(.*/)?files/$"/>
   <action type="Rewrite" url="index.php"/>
  </rule>
  <rule name="Imported Rule 1" stopProcessing="true">
   <match url="^(downloads/.*)" ignoreCase="false" />
   <conditions logicalGrouping="MatchAll" />
  <action type="Rewrite" url="/index.php?sdmon={R:1}" 
appendQueryString="false" />
  </rule>
        <rule name="wordpress - 2" stopProcessing="true">
          <match url="^(.*/)?files/(.*)"/>
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_URI}" pattern=".*wp-content/plugins.*" 
negate="true"/>
          </conditions>
          <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" 
appendQueryString="false"/>
        </rule>
        <rule name="wordpress - 3" stopProcessing="true">
          <match url="^(.+)$"/>
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_URI}" pattern="^.*/wp-admin$"/>
          </conditions>
          <action type="Redirect" url="{R:1}/" redirectType="Permanent"/>
        </rule>
        <rule name="wordpress - 4" stopProcessing="true">
          <match url="."/>
          <conditions logicalGrouping="MatchAny">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" pattern=""/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" 
pattern=""/>
          </conditions>
          <action type="None"/>
        </rule>
        <rule name="wordpress - 5" stopProcessing="true">
          <match url="^([_0-9a-zA-Z-]+/)?(wp-.*)"/>
          <conditions logicalGrouping="MatchAll"/>
          <action type="Rewrite" url="{R:2}"/>
        </rule>
        <rule name="wordpress - 6" stopProcessing="true">
          <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$"/>
          <conditions logicalGrouping="MatchAll"/>
          <action type="Rewrite" url="{R:2}"/>
        </rule>
        <rule name="wordpress - 7" stopProcessing="true">
          <match url="."/>
          <conditions logicalGrouping="MatchAll"/>
          <action type="Rewrite" url="index.php"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

After hitting settings -> permalinks and setting to the regular ?p= setting
this is what the web.config looks like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="wordpress - 2" stopProcessing="true">
          <match url="^(.*/)?files/(.*)"/>
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_URI}" pattern=".*wp-content/plugins.*" 
negate="true"/>
          </conditions>
          <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" 
appendQueryString="false"/>
        </rule>
        <rule name="wordpress - 3" stopProcessing="true">
          <match url="^(.+)$"/>
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_URI}" pattern="^.*/wp-admin$"/>
          </conditions>
          <action type="Redirect" url="{R:1}/" redirectType="Permanent"/>
        </rule>
        <rule name="wordpress - 4" stopProcessing="true">
          <match url="."/>
          <conditions logicalGrouping="MatchAny">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" pattern=""/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" 
pattern=""/>
          </conditions>
          <action type="None"/>
        </rule>
        <rule name="wordpress - 5" stopProcessing="true">
          <match url="^([_0-9a-zA-Z-]+/)?(wp-.*)"/>
          <conditions logicalGrouping="MatchAll"/>
          <action type="Rewrite" url="{R:2}"/>
        </rule>
        <rule name="wordpress - 6" stopProcessing="true">
          <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$"/>
          <conditions logicalGrouping="MatchAll"/>
          <action type="Rewrite" url="{R:2}"/>
        </rule>
        <rule name="wordpress - 7" stopProcessing="true">
          <match url="."/>
          <conditions logicalGrouping="MatchAll"/>
          <action type="Rewrite" url="index.php"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Notice the missing imported rule and the wordpress -1 is missing as well

Attachments (1)

16076.diff (463 bytes) - added by nacin 13 years ago.

Download all attachments as: .zip

Change History (12)

#1 @Frumph
13 years ago

  • Severity changed from normal to major

.. I'm afraid to hit settings -> permalinks and save for everytime I do it's updating my web.config inappropriately. It shouldn't be updating the web.config at all after creating_a_network is done.

#2 @nacin
13 years ago

  • Component changed from General to Rewrite Rules
  • Milestone changed from Awaiting Review to 3.1

This looks pretty bad. Here's a patch to test. This puts iis7_save_url_rewrite_rules() in line with save_mod_rewrite_rules().

@nacin
13 years ago

#3 @nacin
13 years ago

  • Keywords has-patch added
  • Severity changed from major to critical

#4 @Frumph
13 years ago

applied patch, the quick check for is_multisite() patch has indeed made it stop saving on every permalink save.

#5 @nacin
13 years ago

This occurred in 3.0 as well, right? Surprised we didn't catch it then.

#6 @Frumph
13 years ago

No, weirdly enough I don't recall it ever doing it in 3.0 - although I never really needed to until I started working on custom post-type wp_rewrites - so wasn't paying attention.

As far as I remember it didn't.. because I do add extra sites once in awhile and it never adjusted the web.config

#7 follow-up: @westi
13 years ago

While this might fix the issue here does it fix the real bug.

Pretty sure this isn't a regression - I need to get my IIS test bed up and running again so I can pound WP on IIS again.

#8 in reply to: ↑ 7 @nacin
13 years ago

Replying to westi:

While this might fix the issue here does it fix the real bug.

In the sense that this is exactly how multisite prevents .htaccess from being rewritten, yes.

Pretty sure this isn't a regression - I need to get my IIS test bed up and running again so I can pound WP on IIS again.

It isn't as far as I can tell, which leads me to make two observations. One, I'm not sure how it wasn't reported until now. That part is very surprising. Two, this sounds like a critical bug that would prevent anyone from using IIS with multisite, as any hard flush of the rules would reset the web.config file inappropriately.

#9 @Frumph
13 years ago

I have another field of thought on this. That previous to now that it was actually saving new rules, however the rules were saving correctly so no one really paid attention since it didn't mess anything up because the rules were correct.

However, the bug behind the bug is the missing wordpress - 1 not being saved which is how I noticed this in the first place.

#10 @westi
13 years ago

Ok I've read through all the code on this and I am now convinced the nacin's patch is the right way to go.

In general the rule is - if multisite don't touch the htaccess/web.config file :-)

#11 @westi
13 years ago

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

(In [17328]) Don't touch web.config when flushing rewrite rules if it is a multisite install. Fixes #16076 props nacin.

Note: See TracTickets for help on using tickets.