WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#16736 closed defect (bug) (fixed)

Rewrite rules are generated inconsistently for custom taxonomies and /%category%/%postname% permalink structure

Reported by: valentinas Owned by:
Milestone: 3.3 Priority: normal
Severity: normal Version: 3.1
Component: Rewrite Rules Keywords: reporter-feedback
Focuses: Cc:

Description

Steps to reproduce:

  1. Fresh install of WordPress 3.1
  2. Activate dummy custom post type + custom taxonomy plugin (attached, code taken from codex)
  3. Go to Settings->Permalinks, set Custom Structure "/%category%/%postname%" and save
  4. Go to database table wp_options and look for an option "rewrite_rules" it will have 76 rules.
  5. Save permalinks again (or reload permalinks page or just visit permalinks page again)
  6. 4. Go to database table wp_options and look for an option "rewrite_rules" again

Expected result: you should see the same rules as first time, because permalink structure haven't changed.
Actual result: there will be more (104 in my case) rules than first time.

Attachments (1)

test_plugin.php (3.3 KB) - added by valentinas 3 years ago.
dummy custom post type and custom taxonomy plugin. code taken from codex

Download all attachments as: .zip

Change History (37)

valentinas3 years ago

dummy custom post type and custom taxonomy plugin. code taken from codex

comment:1 jghazally3 years ago

  • Cc jghazally added

Ok I tested the Standard Plugin supplied,
The problem is not just /%category%/%postname%/
The steps to test this problem are

  1. set default permalinks for a CPT
  2. set to one of the other fancy permalink options or a custom permalink structure

(you will get a 404 and your re-write rules are not complete. not until you refresh the page or hit save for a second time)
you can do it again by going back to
step 1 (default permalink structure) hitting save
step 2 (any other permalink) hit save - check your re-write rules
step 3 hit save again - check your rewrite rules (they are complete fixed)

in summary you have to hit save / reload the permalinks page twice to get your permalinks working..
hope this helps

Jeff

comment:2 scribu3 years ago

  • Keywords reporter-feedback added

The fact that there are more or less rules is kind of irrelevant. Does this cause any 404 or other errors?

comment:3 valentinas3 years ago

yes, that causes 404

comment:4 sterlo3 years ago

Related? #15943

comment:5 scribu3 years ago

@valentinas: ok, then please post sample URLs that give 404s.

Last edited 3 years ago by scribu (previous) (diff)

comment:6 valentinas3 years ago

Sample URLs:

Permalink structure - Day and name:
http://localhost/test/book/test-book/

Permalink structure - Month and name:
http://localhost/test/book/test-book/

Permalink structure - Numeric:
http://localhost/test/archives/book/test-book

Test case to get 404:

  1. In fresh WP install and activate the dummy plugin that is attached to this ticket
  2. Go to Books->Add New
  3. Enter "test-book" as title and click Publish
  4. Go to Settings->Permalinks and set permalinks to anything else than default.
  5. Go to Books->Books, mouseover on test-book and click "View"

Expected result: the book page is shown
Actual result: 404 occurs

  1. Go to Settings->Permalinks and set permalinks to default
  2. Repeat steps 4 - 7 to test other pemalink structures.

comment:7 scribu3 years ago

  • Owner set to scribu
  • Status changed from new to reviewing

Can't reproduce.

This is how it goes for me:

  1. Activate plugin.
  2. Access wp-admin/options-permalink.php
  3. Go to http://localhost/wp/book/test-book

No 404s. Have you tried deactivating all other plugins and switching to the default theme?

comment:8 valentinas3 years ago

Im doing that on fresh install, empty database and only plugin that is present is the one that's attached to this ticket.

comment:9 RyanMurphy3 years ago

Vanilla install; http://localhost/book/test-book/ doesn't even display a WordPress 404, I get shown the Apache/ubuntu one.

Error log:

[Thu Mar 03 00:02:46 2011] [error] [client ::1] File does not exist: /var/www/book, referer: http://localhost/wp-admin/edit.php?post_type=book

comment:10 follow-up: scribu3 years ago

@RyanMurphy: Do pretty permalinks work at all? Make sure you have your .htaccess file.

comment:11 in reply to: ↑ 10 RyanMurphy3 years ago

Replying to scribu:

@RyanMurphy: Do pretty permalinks work at all? Make sure you have your .htaccess file.

No, they don't.

Using month and name, .htaccess is:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

comment:12 RyanMurphy3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

nevermind me... mod_rewrite got disabled somehow... will re-enable and report back...

comment:13 RyanMurphy3 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

not sure how I closed it, reopening :S

comment:14 scribu3 years ago

Yeah, that's a bug in the trac software itself. It's bitten me a few times as well.

comment:15 RyanMurphy3 years ago

phpinfo() confirms mod_rewrite is loaded, but I can't even get to localhost/sample-page/.

comment:16 pavelevap3 years ago

  • Cc pavelevap@… added

comment:17 RyanMurphy3 years ago

localhost is screwed up somehow (no idea, since nothing has been updated since it last worked), but I tested on a site hosted on an actual server, and that displays the WordPress 404 when I try.

comment:18 RyanMurphy3 years ago

It now works for me after updating from r17485 to r17517

(localhost issues was a configuration issue that was hidden due to me having WordPress in a subdirectory at first)

comment:19 RyanMurphy3 years ago

  • Owner changed from scribu to RyanMurphy
  • Status changed from reopened to reviewing

Narrowed it to r17512 as the revision that fixes it for me.

comment:20 RyanMurphy3 years ago

  • Owner changed from RyanMurphy to scribu

(fixing the trac glitch)

comment:21 follow-up: nacin3 years ago

RyanMurphy and scribu: what browser (including minor version) and browser have you been using?

comment:22 in reply to: ↑ 21 RyanMurphy3 years ago

Replying to nacin:

RyanMurphy and scribu: what browser (including minor version) and browser have you been using?

firefox 3.6.14 and .15 on ubuntu

comment:23 scribu3 years ago

Firefox 4 beta and Chrome 10 on Ubuntu.

comment:24 valentinas3 years ago

  • Keywords reporter-feedback removed

still exists in trunk r17517

comment:25 ryanduff3 years ago

  • Cc ryanduff added
  • Keywords reporter-feedback added

Works for me. Followed steps.

Vanilla 3.1 install. Updated permalink structure to "%category%/%postname%". Created book titled test-book and hit publish. Post shows up when I hit view.

I'm going to assume it may be something w/ your site/server config. Try running it on a public facing server and not local and see what happens.

Here's the url for the test book post I created. No 404 following the steps above...

http://clients.fusionized.com/31test/book/test-book

FWIW, the custom structure you set up only applies to posts (I think). There are a bunch of options when setting up rewrites for custom post types. Its in the codex, but there's also an article here that covers it in depth -> http://shibashake.com/wordpress-theme/custom-post-type-permalinks

comment:26 follow-up: valentinas3 years ago

Have you followed the steps in http://core.trac.wordpress.org/ticket/16736#comment:6 ? In that particular order?
Have you wiped your DB and files before doing so?

Also this is public url to my server:
http://supersonic.lt/test/book/test-book/

I was testing on localhost (MAMP) same result and on the server - same result. And the server is just a general shared hosting one, so this is definitely not a server/site config.

If you want - i can give you username/passw to this test website, just drop me an email: v.bakaitis@…

comment:27 in reply to: ↑ 26 ryanduff3 years ago

Replying to valentinas:

Have you followed the steps in http://core.trac.wordpress.org/ticket/16736#comment:6 ? In that particular order?
Have you wiped your DB and files before doing so?

Yes. This time I followed and I think its the order process you're taking. The permalinks aren't being generated correctly for the CPT so when you add the post and then go update permalinks to generate the rules they're not already in place.

Generally when creating permalinks you want to flush rules when you register the post type (on activation) or manually do it by updating the permalinks via options-permalink.php which should also flush rules.

Per the process in your comment, you're creating a post in the CPT before actually generating the rewrite rules.

Following the preferred/expected method (Register CPT, flush rules, create posts) there's no 404 issue.

comment:28 ryanduff3 years ago

Upon further testing, It seems the Numeric rules break. I set it to Day and Name as well as Month and name and no 404. But when I set to numeric, it broke and resulted in a 404. Ironically that was my choice for the last test to it may have been a fluke. Will do a quick clean install and test one more time choosing something other than default and numeric.

comment:29 ryanduff3 years ago

This time:

  1. Clean Install
  2. Activate Plugin
  3. Set Permalink Structure to Day and Name
  4. Add new book "test-book"; publish
  5. Click view; no 404

comment:30 follow-up: valentinas3 years ago

Ryan, test case is to add book first and set permalinks after that. But $wp_rewrite->flush_rules() after registering post type helps. I will try that on wp-e-commerce (this time on real plugin) and update the ticket with the results.

comment:31 in reply to: ↑ 30 ryanduff3 years ago

Replying to valentinas:

Ryan, test case is to add book first and set permalinks after that. But $wp_rewrite->flush_rules() after registering post type helps. I will try that on wp-e-commerce (this time on real plugin) and update the ticket with the results.

You want to make sure you do it on activation and not registration. I do it on registration in dev, but change to activation once a plugin is released. No need to flush on every admin init.

Let me know how your testing works out.

comment:32 scribu3 years ago

  • Owner scribu deleted

comment:33 scribu3 years ago

Related: #18040

Last edited 3 years ago by scribu (previous) (diff)

comment:34 andy3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

Fixed in [18443].

comment:35 nacin3 years ago

  • Milestone changed from Awaiting Review to 3.3

comment:36 SergeyBiryukov2 years ago

[18443] was only for custom post types, see [19930] for custom taxonomies.

Note: See TracTickets for help on using tickets.