• So I’m using mod_rewrite for a couple of plugins (Now Reading, and one I made myself), and bunched all of my custom rewrite rules together (so yes, it’s messy – please excuse me):

    function nr_mod_rewrite( $rules ) {
    	global $wp_rewrite;
    	$rules['^gallery/([^/]+)/([^/]+)/?$'] = 'index.php?fg_gallery=true&fg_set=' . $wp_rewrite->preg_index(1) . '&fg_single=' . $wp_rewrite->preg_index(2);
    	$rules['^gallery/([^/]+)/?$'] = 'index.php?fg_gallery=true&fg_moreset=' . $wp_rewrite->preg_index(1);
            $rules['^gallery/?$'] = 'index.php?fg_gallery=true';
    	$rules['^library/([0-9]+)/?$'] = 'index.php?now_reading_id=' . $wp_rewrite->preg_index(1);
    	$rules['^library/tag/([^/]+)/?$'] = 'index.php?now_reading_tag=' . $wp_rewrite->preg_index(1);
    	$rules['^library/search/?$'] = 'index.php?now_reading_search=true';
    	$rules['^library/([^/]+)/([^/]+)/?$'] = 'index.php?now_reading_author=' . $wp_rewrite->preg_index(1) . '&now_reading_title=' . $wp_rewrite->preg_index(2);
    	$rules['^library/([^/]+)/?$'] = 'index.php?now_reading_author=' . $wp_rewrite->preg_index(1);
    	$rules['^library/?$'] = 'index.php?now_reading_library=true';
    	return $rules;
    }
    add_filter('rewrite_rules_array', 'nr_mod_rewrite');

    My problem is thus:

    Some of the rules work fine and dandy. The following rewrite rules don’t work at all, the variables don’t appear in $wp->query_vars or anything (yes, I registered them – see below).

    $rules['^gallery/([^/]+)/?$'] = 'index.php?fg_gallery=true&fg_moreset=' . $wp_rewrite->preg_index(1);
    $rules['^gallery/?$'] = 'index.php?fg_gallery=true';
    $rules['^library/search/?$'] = 'index.php?now_reading_search=true';
    $rules['^library/([^/]+)/?$'] = 'index.php?now_reading_author=' . $wp_rewrite->preg_index(1);
    $rules['^library/?$'] = 'index.php?now_reading_library=true';
    function nr_query_vars( $vars ) {
    	$vars[] = 'now_reading_library';
    	$vars[] = 'now_reading_id';
    	$vars[] = 'now_reading_tag';
    	$vars[] = 'now_reading_search';
    	$vars[] = 'now_reading_title';
    	$vars[] = 'now_reading_author';
    	$vars[] = 'fg_gallery';
    	$vars[] = 'fg_single';
    	$vars[] = 'fg_moreset';
            $vars[] = 'fg_set';
    	return $vars;
    }
    add_filter('query_vars', 'nr_query_vars');

    It’s as though the rules clash somehow, they all give me 404s unless I’m viewing the most specific pages (ones with author and title, or set and photograph). Can anyone enlighten me on how to get it working?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I had the same problem with rewrite rules beginning with ^library. I changed the word to ^libary and everything worked fine.

    When using ^library, the rewrite rule persisted even when I deleted the .htaccess file altogether, and GET variables were lost. Very bizarre.

    Another site suggested that there was a possible conflict with an aliased folder on the host. However, in my httpd.conf there are no references to library at all.

    It may just be an Apache bug. It would be nice to find a solution so I don’t have to rename the entire /library/ part of my site ??

    Sorry, what I wrote was not true… my problem came from redirecting requests starting with /library… to /library.php, so that my redirects were in turn being trapped by the same rule.

    As soon as I gave my script a different name from the original path, it started working.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Rewrite Rules – Some Don’t Work?’ is closed to new replies.