The MU forums have moved to WordPress.org

New blogs not working with Wordpress MU and IIS7 (8 posts)

  1. mathewda
    Member
    Posted 14 years ago #

    I'm using IIS7 on windows server 2008 to run Wordpress MU 2.7.1. I've setup Wordpress MU just fine and my main blog seems to work as expected. Today I added a new blog "myblog". After adding it, the new blog shows up in wp-admin for the main blog and I received several notification emails with the password for the new blog, etc. However, when I go to view the blog at http://www.domain.com/myblog or try to access the admin at http://www.domain.com/myblog/wp-admin I get 404 errors from IIS. Is there another rewrite rule to configure in IIS to get additional blogs to work? Is there something in wordpress mu I need to configure differently?

    I configured Wordpress Mu to use sub directories for new blogs and the web.config file in wwwroot contains the following rewrite section:
    <rewrite>
    <rules>
    <clear />
    <rule name="Main Rule" enabled="true" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll">
    <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>

  2. mathewda
    Member
    Posted 14 years ago #

    I'm starting to think this is some kind of wordpress mu config thing and not something IIS7 specific. Can anyone point me to some resources on how wordpress mu figures out that "/myblog" is a separate blog from "/"? I disabled IIS7's 404 error and now I get a 404 from wordpress instead. I also did a print_r on $current_site and $current_blog from my 404 template and they both seem to still point to my main blog. I'm thinking that when I go to http://www.domain.com/myblog that it for some reason is looking on my main blog for something at /myblog and not recognizing that /myblog is actually a different blog, which would explain the 404.

    Can anyone explain what could be causing wordpress mu to not see /myblog as a separate blog from my main blog? Are there any good articles or descriptions that someone can point me to that explain how wordpress mu goes from client request to serving up the right blog when using sub directories for blogs?

  3. andrea_r
    Moderator
    Posted 14 years ago #

    It's the function of mod_rewrite. I'm not a Windows gal, but the last I knew is that you had to have a paid module for IIS to handle the rewrite rules properly.

    The process WPMU uses is this:
    http://wpmututorials.com/basics/mu-is-virtually-yours/

  4. mathewda
    Member
    Posted 14 years ago #

    IIS7 has a URL rewrite module that you can install that appears to work. Wordpress does have some instructions on their site for the rule that you have to include and from what I hear it's going to be a little more obvious in the admin for the 2.8 version.

    Thanks for the link, I had actually just figured out that much of how wordpress mu is working right before you posted it. I think my problem is some sort of configuration issue or some kind of missing rewrite rule, although I'm leaning toward config issue right now...

    The wpmu-settings.php file appears to be where some of the magic happens to tell wordpress which blog/site should be displayed. Part deals with reading the original request url from REQUEST_URI and then it does some lookup in the wp_blogs or wp_sites tables to check and see if that site/path exists as a separate blog or not. I did find something interesting which could be part of my problem. It appears that the domain is read in and the www. is stripped off before the database lookup. So apparently it's looking for domain.com and not http://www.domain.com when it queries the database for a matching site and path. My database had http://www.domain.com in the actual database records, which was causing it to not find a match and therefore assume it's a 404 error on the main blog site. I manually edited the database entry to be domain.com instead of http://www.domain.com in the wp_blogs table for my "myblog" site. After doing this I can navigate to http://www.domain.com/myblog and it loads the content for that new blog.. however none of the style sheets or images appear to load (I think it's looking for them in a /myblog/wp-content/themes folder instead of /wp-content/themes). I also tried to go to the wp-admin and it just redirects me back to /myblog. Pages and posts appear to work though because I can go to /myblog/about and successfully see the about page.

    Just as an fyi, my VHOST setting is 'no' in my wp-config.php file. I am using sub directories so I'm assuming that's fine but please let me know if that has anything to do with this.

  5. andrea_r
    Moderator
    Posted 14 years ago #

    "Just as an fyi, my VHOST setting is 'no' in my wp-config.php file. I am using sub directories so I'm assuming that's fine but please let me know if that has anything to do with this. "

    That part's fine.

    "I manually edited the database entry to be domain.com instead of http://www.domain.com in the wp_blogs table for my "myblog" site. After doing this I can navigate to http://www.domain.com/myblog and it loads the content for that new blog.. however none of the style sheets or images appear to load (I think it's looking for them in a /myblog/wp-content/themes folder instead of /wp-content/themes)."

    look in the HTML source of the page. My guess is it's looking for them at the WWW or not, and what you really need to do is configure the server to answer to the non-www and just use that.

  6. mathewda
    Member
    Posted 14 years ago #

    Ok, I think I have this working now...

    It appears to be a combination of two issues.

    • Apparently Wordpress Mu needs multiple rewrite rules in IIS 7 not just one.
    • You should omit the www. before your domain in several places or you're going to encounter some strange issues

    At one point I decided it would be a good idea to see what was in the .htaccess files even though IIS 7 is not using them. What I found was there was several rewrite rules in the .htaccess file in my wwwroot folder (See below for it's contents). I went into IIS 7's url rewrite configuration and disabled my previous rewrite rule and did an "import rules..." from my .htaccess file. Before the import would work I had to remove the line that said "RewriteBase" to get the .htaccess file to import (not sure what the implications of this are but it seems to not be causing any issues). 7 rules were imported. I then opened web.config and changed all references of {SCRIPT_NAME} to {URL}, as mentioned in Importing Apache mod_rewrite Rules. At this point some of my problems started to go away (such as css and images loading correctly for the secondary blog, etc). See below for the changes to my web.config for the URL Rewrite modules.

    I then attempted to log into my secondary blog's wp-admin. However what I kept getting was the login page (after logging in it just kept redirecting me back to there, even if I directly typed in domain.com/wp-admin). What I eventually figured out was the www. needed to be removed from several places for both my main blog and my secondary blog. The first place was in the wp-admin for the primary blog (go to Site Admin -> Blogs), then remove the www. in the domain property and click the update options button. I also had to change define('DOMAIN_CURRENT_SITE', 'www.domain.com' ); to define('DOMAIN_CURRENT_SITE', 'domain.com' ); in my wp-config.php file.

    It now appears that the site is working as expected. Let me know if there are any problems with this approach or anything I might have missed here.

    My IIS 7 web.config file in wwwroot changed from this:

    <rewrite>
                <rules>
                    <clear />
                    <rule name="Main Rule" stopProcessing="true">
                        <match url=".*" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="index.php" />
                    </rule>
    </rewrite>

    To this:

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

    Contents of .htaccess in wwwroot folder:

    RewriteEngine On
    RewriteBase /
    
    #uploaded files
    RewriteRule ^(.*/)?files/$ index.php [L]
    RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
    RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteCond %{REQUEST_URI} ^.*/wp-admin$
    RewriteRule ^(.+)$ $1/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
    
    <IfModule mod_security.c>
    <Files async-upload.php>
    SecFilterEngine Off
    SecFilterScanPOST Off
    </Files>
    </IfModule>
  7. tannedchick
    Member
    Posted 14 years ago #

    life saver!!!!
    thanks!!!

  8. wazzy
    Member
    Posted 14 years ago #

    Hi,
    I've decided to use sub domains on my mu wordpress install on a IIS 7 hosted account, and while I don't have a web.config file in place things seem to be working find as long as I have permalinks as follows:
    /index.php/%year%/%monthnum%/%postname%/

    If I have just:
    /%year%/%monthnum%/%postname%/
    I get an error.

    Does anyone have a solution to this problem? If I have to have a web.config is there a template I can start from that is known to work with wordpress mu?

    Thanks!

About this Topic