[wp-hackers] Custom permalinks with the Rewrite API
Mike Schinkel
mikeschinkel at newclarity.net
Fri Oct 9 18:46:34 UTC 2009
Eric,
I have a custom plugin I've written for my own use that makes
extensive use of URL rewrite. It's not in a state to be released but
is something I could send you if you like. It powers http://pm-sherpa.com
. Email me and I'll forward to you.
BTW, I would not recommend using a colon in your URL like you have. A
colon is a reserved character in the URI spec and as such will often
get encoded by various softwares (i.e. title%3Adesc instead of
title:desc):
2.2. Reserved Characters
(From http://www.ietf.org/rfc/rfc2396.txt)
Many URI include components consisting of or delimited by, certain
special characters. These characters are called "reserved", since
their usage within the URI component is limited to their reserved
purpose. If the data for a URI component would conflict with the
reserved purpose, then the conflicting data must be escaped before
forming the URI.
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
"$" | ","
The "reserved" syntax class above refers to those characters that
are
allowed within a URI, but which may not be allowed within a
particular component of the generic URI syntax; they are used as
delimiters of the components described in Section 3.
Instead I'd suggest one of these based on the unreserved characters:
-- title-desc
-- title_desc
-- title.desc
-- title!desc
-- title~desc
-- title*desc
-- title(desc)
Not sure which I like the best.
2.3. Unreserved Characters
Data characters that are allowed in a URI but do not have a reserved
purpose are called unreserved. These include upper and lower case
letters, decimal digits, and a limited set of punctuation marks and
symbols.
unreserved = alphanum | mark
mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
Unreserved characters can be escaped without changing the semantics
of the URI, but this should not be done unless the URI is being used
in a context that does not allow the unescaped character to appear.
HTH.
-Mike Schinkel
WordPress Custom Plugins
http://mikeschinkel.com/custom-wordpress-plugins/
On Oct 9, 2009, at 11:48 AM, Eric Martin wrote:
> I want to be able to allow users to custom sort a group of posts by
> adding a custom rewrite rule. I'm thinking of the following structure:
>
> /some-slug/sort/title:desc/
> /some-slug/sort/date:desc/
> /some-slug/sort/downloads:desc/
>
> I have tried doing this a couple of ways, but can't seem to get it to
> work:
> - some-slug as a page
> - some-slug as a category and using permalink structure of /%category
> %/
> %postname%/
>
> One catch is that the sorting should still work with pagination.
> Depending on which they do first, the URI could look different:
> /some-slug/sort/title:desc/page/2
> /some-slug/page/2/sort/title:desc/
>
> I tried using an endpoint first, but that doesn't seem to work with 2
> endpoints together, which makes sense.
>
> So, I'm curious if others have done this and if there are any
> suggestions on the "best" approach. I'd love to see some examples and
> appreciate any help you can provide.
>
> On a side note, there doesn't seem to be a whole lot of good
> documentation or examples surrounding the Rewrite API. What
> information is out there (on blogs and such) is often outdated or
> misleading. Based on what I'm able to learn through this processes, I
> hope to be able to create some helpful information and examples on how
> the Rewrite API works.
>
> --
> Eric Martin
> http://www.ericmmartin.com
> http://twitter.com/ericmmartin
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list