• kemper-boyd

    (@kemper-boyd)


    I need to rewrite an address like this:

    http://example.com/galleria/artist-name

    so that it goes to the gallery.php page with a variable containing ‘artist-name’. I used the same syntax as in the wp rewrite documentation and while it works fine on my local wordpress install, on the real server it has a strange behavior: the original URL is accepted (i.e. it doesn’t end in a 404) but it gets rewritten to

    http://example.com/gallery

    (I mean actually rewritten in the browser’s address bar) and the variable is not set.

    Rules used:

    // REWRITE RULES (per gallery) {{{
    add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
    add_filter('query_vars','wp_insertMyRewriteQueryVars');
    add_filter('init','flushRules');
    
    // Remember to flush_rules() when adding rules
    function flushRules(){
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }
    
    // Adding a new rule
    function wp_insertMyRewriteRules($rules)
    {
        $newrules = array();
        $newrules['(galleria)/(.*)$'] = 'index.php?pagename=gallery&galleryname=$matches[2]';
        return $newrules + $rules;
    }
    
    // Adding the id var so that WP recognizes it
    function wp_insertMyRewriteQueryVars($vars)
    {
        array_push($vars, 'galleryname');
        return $vars;
    }

    WordPress 2.9.2 both in my local test environment, and on the running online server. What can cause this behavior?

    Thanks

The topic ‘Problem with WP Rewrite’ is closed to new replies.