WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 8 months ago

Last modified 4 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:

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 (4)

comment:1 johnbillion2 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/.

comment:2 scribu2 years ago

  • Cc scribu added

comment:3 c3mdigital8 months 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

apps/about/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$	
apps/about/([^/]+)/(feed|rdf|rss|rss2|atom)/?$	
apps/about/([^/]+)/page/?([0-9]{1,})/?$	
apps/about/([^/]+)/?$

comment:4 markoheijnen4 months ago

  • Milestone Awaiting Review deleted

Clearing out the milestones for closed tickets on Awaiting Review

Note: See TracTickets for help on using tickets.