Opened 5 years ago
Closed 3 years ago
#5989 closed enhancement (wontfix)
Canonical Rewrite Misinterprets Some Queries
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Canonical | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | filosofo |
Description
Here's how to see the problem:
- Let's say you have a category named "fun" that has category id of 15
- Let's say you have a post under category "fun" for January 22, 2008
- Your permalink structure is /%category%/%year%/%monthnum%/%day%/%postname%/
If you request http://www.example.com/fun/2008/01/22/ then you get (as expected) an archive of all the posts categorized under "fun" on January 22, 2008.
You would expect to get the same thing for http://www.example.com/?year=2008&monthnum=1&day=22&cat=15, and if you were using default (i.e. no) permalinks, that is what you get with that request. You would also expect canonical redirect to send a request for http://www.example.com/?year=2008&monthnum=1&day=22&cat=15 to http://www.example.com/fun/2008/01/22/.
Instead, canonical redirect takes http://www.example.com/?year=2008&monthnum=1&day=22&cat=15, ignores the cat query arg, and redirects to http://www.example.com/2008/01/22/
The general problem is that canonical redirect doesn't do anything with the main permalinks setting. My patch creates a new function, get_permalink_from_query, which attempts to generate a permalink from the wp_query query vars, using the main permalinks setting. If it can't, it just returns false.
The patch also has canonical_redirect attempt to use this function first; if it fails, it goes on to try the existing permalink-generation methods.
Attachments (1)
Change History (9)
I would be careful about this, to make sure that pagination works on this type of URL, before deciding it is OK to canonically redirect to it. See #5331 for an example of where pagination does not work for some permalink structures, for some URLs that might seem logical.
- Component changed from General to Canonical
- Owner changed from anonymous to markjaquith
- Keywords needs-patch added; has-patch removed
- Milestone changed from 2.9 to Future Release
- Type changed from defect (bug) to enhancement
DB:~/Sites/wp $ wptest http://core.trac.wordpress.org/attachment/ticket/5989/canonical_rewrite.diff patching file wp-includes/link-template.php Hunk #1 FAILED at 286. 1 out of 1 hunk FAILED -- saving rejects to file wp-includes/link-template.php.rej patching file wp-includes/canonical.php Hunk #1 FAILED at 33. Hunk #2 succeeded at 52 with fuzz 2 (offset 4 lines). Hunk #3 succeeded at 81 with fuzz 1 (offset 24 lines). Hunk #4 FAILED at 188. 2 out of 4 hunks FAILED -- saving rejects to file wp-includes/canonical.php.rej

see 7101