Opened 12 months ago

Last modified 12 months ago

#20688 new defect (bug)

Forward slash in custom taxonomy rewrite causes 404s because of (unnecessary?) attachment rule

Reported by: harikaram Owned by:
Priority: normal Milestone: Awaiting Review
Component: Rewrite Rules Version: 3.3.2
Severity: normal Keywords:
Cc: scribu

Description

I implement a custom taxonomy with a rewrite that is designed to create urls like:

"/apps/about/sometag"

        $name = 'apps';
        register_taxonomy($name.'-tag', $name.'-post', array(
            'label' => ucfirst($name) . ' Tags',
            'public' => true,
            'has_archive' => true,
            'hierarchical' => false,
            'update_count_callback' => '_update_post_term_count',
            'rewrite' => array('slug' => "$name/about", with_front=>true)
        ));

However I was getting a 404 (yes I was flushing the rules) unless I changed the '/' to say a '-'. Upon inspection of the rules, I found this one whose precedence was causing the problem:

'apps/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]'

Upon removing it inside the "rewrite_rules_array" hook, the problem was solved.

It seems odd to me that this generic rule exists and rewrites to an attachment of all things...

Change History (2)

Do you have a custom post type with the slug 'apps'? If so, that's the rewrite rule that handles attachments belonging to your apps post type, eg. /apps/post-name/attachment-name/.

  • Cc scribu added
Note: See TracTickets for help on using tickets.