• Resolved Jarod Thornton

    (@jarmerson)


    Hi,

    I’ve had a problem with permalinks and cannot for the life of me find a solution. It happens at random and seemingly without provocation.

    What happens is I wake up one random day and a client reports Page Not Found issues on their site. So I pull up their blog and sure enough blog posts are not found.

    I check another client blog and it’s the same issue. I have to then go in one-by-one and fix. However, all it takes is logging into the admin area and visiting the permalinks page – it suddenly works without any action except visiting the permalink settings page in admin.

    I did try to see if updating a plugin would do the trick. So I tried one custom plugin and it didn’t use the WordPress’ $wp_rewrite global. So I tried a more well known plugin, Yoast SEO – that did the trick site-wide.

    The problem persists at random. While that did flush the cache or however it works, the problem returns at random.

    I’ve searched and searched for a few weeks without luck of finding a solution or if I found something I didn’t know if it would work and simply don’t have the experience to implement i.e. WordPress’ $wp_rewrite global – I also attempted to update .htaccess and that didn’t work.

    I would greatly appreciate insight as this is costly for both SEO and traffic.

    Thank you

Viewing 1 replies (of 1 total)
  • Thread Starter Jarod Thornton

    (@jarmerson)

    I believe I found the culprit in a custom plugin I’ve been working on. It’s been very stable, but a few lines that were added and never checked up on appear to have caused my rewrite flush issues.

    Here’s the code…

    // Remove Category Base //
    // Refresh rules on activation/deactivation/category changes
    register_activation_hook(__FILE__, 'no_category_base_refresh_rules');
    add_action('created_category', 'no_category_base_refresh_rules');
    add_action('edited_category', 'no_category_base_refresh_rules');
    add_action('delete_category', 'no_category_base_refresh_rules');
    function no_category_base_refresh_rules() {
    	global $wp_rewrite;
    	$wp_rewrite -> flush_rules();
    }
    
    register_deactivation_hook(__FILE__, 'no_category_base_deactivate');
    function no_category_base_deactivate() {
    	remove_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');
    	// We don't want to insert our custom rules again
    	no_category_base_refresh_rules();
    }
    
    // Remove category base
    add_action('init', 'no_category_base_permastruct');
    function no_category_base_permastruct() {
    	global $wp_rewrite, $wp_version;
    	if (version_compare($wp_version, '3.4', '<')) {
    		// For pre-3.4 support
    		$wp_rewrite -> extra_permastructs['category'][0] = '%category%';
    	} else {
    		$wp_rewrite -> extra_permastructs['category']['struct'] = '%category%';
    	}
    }
    
    // Add our custom category rewrite rules
    add_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');
    function no_category_base_rewrite_rules($category_rewrite) {
    	//var_dump($category_rewrite); // For Debugging
    
    	$category_rewrite = array();
    	$categories = get_categories(array('hide_empty' => false));
    	foreach ($categories as $category) {
    		$category_nicename = $category -> slug;
    		if ($category -> parent == $category -> cat_ID)// recursive recursion
    			$category -> parent = 0;
    		elseif ($category -> parent != 0)
    			$category_nicename = get_category_parents($category -> parent, false, '/', true) . $category_nicename;
    		$category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
    		$category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
    		$category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';
    	}
    	// Redirect support from Old Category Base
    	global $wp_rewrite;
    	$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
    	$old_category_base = trim($old_category_base, '/');
    	$category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';
    
    	//var_dump($category_rewrite); // For Debugging
    	return $category_rewrite;
    }

    I have no use for it so I don’t even care what and why it doesn’t work. ??

Viewing 1 replies (of 1 total)
  • The topic ‘Page Not Found – Multisite – Randomness’ is closed to new replies.