• 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    When I bring the theme into the network, it doesn’t work.

    What’s “it” 🙂 You need to be more descriptive here.

    Does ANY theme work?

    Does the theme work, but not the CSS?

    Thread Starter bigdaddyteemoe

    (@bigdaddyteemoe)

    “IT” is the topic in question: the url rewrite rule.

    Short answer is, I didn’t flush the rewrite rules when activating the theme. After a flush, it worked as designed.

    A better answer is, after quite a bit of frustration, I changed my rewrite rule to an endpoint which was MUCH simpler–but came with a HUGE drawback as it’s codex page is missing key information.

    Endpoints set their query variable equal to whatever comes after it.

    The code for such is super simple:

    add_action('init', 'my_add_endpoints');
    
    function my_add_endpoints()
    {
    	add_rewrite_endpoint('myendpoint', EP_PAGES);
    
    }

    So this url:

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

    becomes:

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

    Then to call it in your theme/plugin:

    if(isset($wp_query->query_vars['myendpoint'])) {
    	//do some stuff
    }

    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, and if anyone is listening, add the necessary info in the codex.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress Network / IIS URL rewrite’ is closed to new replies.