Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a theme that has some custom rewrite rules built in to it. The problem is that they are not working with WP multisite. On the install I use to build themes (which is outside of the network), it works fine. When I bring the theme into the network, it doesn't work.

funcitons.php

add_rewrite_rule('^prop/([^/]*)/?','index.php?pagename=prop&mls=$matches[1]','top');

add_filter('query_vars', 'add_mls');

function add_mls($public_query_vars) {
    $public_query_vars[] = 'mls';
    return $public_query_vars;
}

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>        

Now, the part that I see that is similar, but not identical is "Wordpress Rule 3", where in my test site, it looks like this:

<rule name="wordpress" 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>

So I went ahead and added the rule from my dev site to the network--but I still don't get anything. Any pointers?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

First, I didn't flush the rewrite rules so, or course, the rule wasn't being included.

Second, I ended up going with a MUCH simpler solution to passing the variable to any page with the template applied, which was add_rewrite_endpoint.

add_action('init', 'my_add_endpoints');

function my_add_endpoints()
{
    add_rewrite_endpoint('myendpoint', EP_PAGES);

}

!IMPORTANT - add_rewrite_endpoint registers a query var for you and sets that var's value to whatever directly follows it.

So this url:

http://mysite.com/mypage/myendpoint/myvalue

becomes:

http://mysite.com/index.php?pagename=mypage&myendpoint=myvalue

It took me two days to eventually figure out what should have already been written in the codex. I hope this helps whomever comes across it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.