Make WordPress Core

Opened 6 years ago

Closed 5 years ago

Last modified 13 months ago

#20688 closed defect (bug) (invalid)

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

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


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


        $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 (5)

#1 @johnbillion
6 years ago

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/.

#2 @scribu
6 years ago

  • Cc scribu added

#3 @c3mdigital
5 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Tested using supplied register taxonomy code and no additional attachment rewrite rules were created.

The following rules were created as expected


#4 @markoheijnen
4 years ago

  • Milestone Awaiting Review deleted

Clearing out the milestones for closed tickets on Awaiting Review

#5 @polevaultweb
13 months ago

@harikaram try registering the taxonomy earlier than the post type.

Note: See TracTickets for help on using tickets.