Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#16736 closed defect (bug) (fixed)

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

Reported by: valentinas's profile 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 14 years ago.
dummy custom post type and custom taxonomy plugin. code taken from codex

Download all attachments as: .zip

Change History (37)

@valentinas
14 years ago

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

#1 @jghazally
14 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

#2 @scribu
14 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?

#3 @valentinas
14 years ago

yes, that causes 404

#4 @sterlo
14 years ago

Related? #15943

#5 @scribu
14 years ago

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

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

#6 @valentinas
14 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.

#7 @scribu
14 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?

#8 @valentinas
14 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.

#9 @RyanMurphy
14 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

#10 follow-up: @scribu
14 years ago

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

#11 in reply to: ↑ 10 @RyanMurphy
14 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

#12 @RyanMurphy
14 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...

#13 @RyanMurphy
14 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

not sure how I closed it, reopening :S

#14 @scribu
14 years ago

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

#15 @RyanMurphy
14 years ago

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

#16 @pavelevap
14 years ago

  • Cc pavelevap@… added

#17 @RyanMurphy
14 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.

#18 @RyanMurphy
14 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)

#19 @RyanMurphy
14 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.

#20 @RyanMurphy
14 years ago

  • Owner changed from RyanMurphy to scribu

(fixing the trac glitch)

#21 follow-up: @nacin
14 years ago

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

#22 in reply to: ↑ 21 @RyanMurphy
14 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

#23 @scribu
14 years ago

Firefox 4 beta and Chrome 10 on Ubuntu.

#24 @valentinas
14 years ago

  • Keywords reporter-feedback removed

still exists in trunk r17517

#25 @ryanduff
14 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

#26 follow-up: @valentinas
14 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@…

#27 in reply to: ↑ 26 @ryanduff
14 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.

#28 @ryanduff
14 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.

#29 @ryanduff
14 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

#30 follow-up: @valentinas
14 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.

#31 in reply to: ↑ 30 @ryanduff
14 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.

#32 @scribu
14 years ago

  • Owner scribu deleted

#33 @scribu
13 years ago

Related: #18040

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

#34 @andy
13 years ago

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

Fixed in [18443].

#35 @nacin
13 years ago

  • Milestone changed from Awaiting Review to 3.3

#36 @SergeyBiryukov
13 years ago

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

Note: See TracTickets for help on using tickets.