Make WordPress Core

Opened 11 years ago

Closed 10 years ago

Last modified 5 years ago

#20688 closed defect (bug) (invalid)

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

Reported by: harikaram's profile 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 (6)

#1 @johnbillion
11 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
11 years ago

  • Cc scribu added

#3 @c3mdigital
10 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
9 years ago

  • Milestone Awaiting Review deleted

Clearing out the milestones for closed tickets on Awaiting Review

#5 follow-up: @polevaultweb
6 years ago

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

#6 in reply to: ↑ 5 @ianpegg
5 years ago

Replying to polevaultweb:

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

@polevaultweb -- your suggestion fixed the issue for me, thanks!

Note: See TracTickets for help on using tickets.