• Hi all, this has come up before in Support, and if you go to the Settings -> Permalink page, and just hit Save, it ‘fixes’ it, however in my case it comes back daily, which isn’t great.

    Basically when it’s happening, if you click on a Brand link (eg mysite.com/brand/fancybrand) it redirects to a 404 page error. (Hit the Permalink ‘save’, and works again..for a day.)

    There’s another error that occurs, not sure if related, but if you also try filtering with a brand, the page doesn’t show any results. (URL looks like mysite.com/shop/?filter_brand=fancybrand). Also fixed when ‘Saved’.

    Any insight why this is happening, or how to get it to stop ‘resetting’?

    I’m using the Perfect Brands plugin on the Woodmart theme, one other odd thing is when clicking the /brand/* URL, it actually redirect to mysite.com/woodmart_slide/fancybrand – I’ve reached out to the theme company as well, but they seem puzzled..

    Appreciate any help in sorting this out, or how to troubleshoot further, thanks! (I’ve tried emailing the Brands plugin company as well, but they apparently don’t offer any support on the ‘free’ version.)

    – Dave

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    When you load the permalink settings screen, it causes all the rewrite rules to be flushed and regenerated. (fun fact: you don’t even need to save, loading the page will do). The rewrite rules are generally saved in the options table, which WP then fetches on each request to figure out how to route a request.

    Somehow, the rewrite rules are being corrupted, either in the DB, or when WP fetches them. Unless you can find a way on demand to cause rewrites to fail as they eventually do on their own, debugging will be a difficult process. The usual process involves switching to a default twenty* theme and deactivating all plugin except the one that registers the “brand” object. Then test. Usually everything now works. Restore theme and plugins, one at a time, testing after each until the problem recurs.

    If you cannot induce the problem for testing and need to wait for it to occur, it’s going to be a long drawn out process while your site behaves oddly. It’s possible to do these tests in a separate instance of your site so regular users are not disturbed, but waiting for something to maybe happen is far from ideal.

    Thread Starter davefrombc

    (@davefrombc)

    Hey there, thanks for all this! That’s interesting it doesn’t even need to be saved.

    It had stopped happening for the last few days, but came back today. Frustrating it’s so hard to troubleshoot, figured it was something internal like that. It’s just a small site without too much traffic so we don’t run any mirrors or staging, etc..

    Thanks again for the info, still open to any other suggestions to figuring out what might be causing this!

    As a band-aid, is it possible to set ‘opening the Permalink page’ as some kind of CRON job so it’s at least actively keeping it going? (Until it gets sorted permanently.)

    Moderator bcworkz

    (@bcworkz)

    The function that is called when you load the permalinks settings screen is flush_rewrite_rules(), which clears the currently saved rules and regenerates them. So yes, that function could be periodically called from wp-cron or server CRON.

    Something else you might try is adding your own rewrite rule that serves the same purpose. Your own rule might be more “sticky” than the one that should normally be in place. For example:

    add_action( 'init',  function() {
        add_rewrite_rule( 'brand/([a-z0-9-]+)[/]?$', 'index.php?brand=$matches[1]', 'top' );
    } );

    I’m assuming “brand” in the index.php URL is the correct query var, but have no way to confirm. Visit the permalinks settings screen after adding the code somewhere like your theme’s functions.php.

    If your theme is subject to periodic updates, this code will be removed during updates. If this solves the problem, it’d be better to make it into a simple, custom plugin. It’s easier to do than it might sound.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Getting 404 Error on Brand links, also Filter issues’ is closed to new replies.