Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Let me guess: Your custom permalink string starts with %category%, doesn’t it?

    The reason this happens has to do with the way the rewrite code works. It’s complicated, but the short answer is that using “category” in the permalinks string is only there for show, really. It will cause the first category to be in the generated URL for single post permalinks, but WordPress itself doesn’t use category as a selector for single posts when a more specific one is available. But when a more specific one is not available, then it maps to that string, meaning that the random text gets mapped to the category selector.

    However, then your link goes on to specify the category directly with the following /category/whatever piece, which overrides it. Thus WordPress never sees the random text and has no chance to correct.

    Quick fix: Stop using %category% in your permalink string. You’ll find that those 200’s will get replaced with 301’s to redirect properly, or 404’s in some cases.

    Thread Starter Anonymous User 319290

    (@anonymized-319290)

    Could you provide any links to more info on this subject?

    changing my url structure would be a fix of last resort for me.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    No, I have no links on the topic.

    And such a fix would really be your *only* resort, not the last one. The 200’s you’re getting is a consequence of the move combined with the use of %category% and the way the rewrite system works. It’s not fixable except by eliminating one of the conditions causing it.

    Thread Starter Anonymous User 319290

    (@anonymized-319290)

    So what’s amusing about this is that it applies to ANY wordpress site that uses %category% (or presumably tag, author, or postname) as the start of the permalink structure.

    Insert any text of any length before the category in the url, and that url will magically become a part of your website.

    I don’t know if that technically meets the definition of a bug, but at the very least it is a grotesque behavior that deserves either to be fixed, or documented.

    If you are using one of these permalink structures, you not only have to worry about possible performance issues (with large numbers of pages), but also the fact that your site will return an infinite number of non-existent urls as 200-OK. Indexing issues can’t be far behind.

    This problem is probably limited in scope to occasional misspelled links and urls, but if you do a directory change, as I did, it starts looking a little more alarming.

    I do hope the permalink overlords give this matter some thought.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    It’s deeper than that, actually. If you use %category% as part of the permalink structure, then you can change out that section with literally anything in any single post link and still get the single post.

    The problem here is the way the rewrite system parses the links. That custom permalink is supposed to be only for single post permalinks. The way it works is that it parses the URL according to that structure, and then breaks it down into pieces.

    So, for example, your post here has this URL:
    http://www.sierradescents.com/gear/2009/06/13/black-diamond-tents.html

    Your structure appears to be “category/year/month/day/postname.html”. So it parses that into there:
    category=gear
    year=2009
    month=6
    day=13
    postname=black-diamond-tents

    And so forth. This happens with pretty much every URL, using various rulesets.

    Next, it takes a look at what it’s got so far, and gives you the most specific thing it can based on that. In your case, it knows the exact postname and date, which is enough to identify the specific post, so it ignores the category. This is why the category can be anything in the URL. Notice that http://www.sierradescents.com/RANDOM/2009/06/13/black-diamond-tents.html works just as well.

    This occurs anytime you use category anywhere in the custom permalink string. Why? Because a category can *never* help to identify a specific post. It’s never needed. If you know enough to get the specific single post, then you don’t need the category. Posts can’t share postnames or ID’s. If you leave those out, you don’t have a specific post to get anymore.

    And since this is the single-post permalink string being used here, the category is basically never needed at all. It’s only there for show, and because some people think that having category in the permalink helps in some fashion. It doesn’t, but it’s easier to let them have it than to try to convince them otherwise.

    The correct fix is to remove %category% from the possible permalink tags, IMO. But too many people want it, so in it stays. My advice: just don’t use it. You don’t need it. It only causes difficulty. It’s also not specific. Posts can have multiple categories, which one should it use? There’s no indication for that use case. It’s poorly defined and a bad idea in general.

    “Posts can have multiple categories, which one should it use?”

    All of them like /tents/bigtents/sunshineprooftents/

    Obviously it doesn’t at the moment, but I think that should be an option. Especially since it sounds like it would be super easy to add.

    I have learned a lot from your posts Otto. Other than looks, there is one undeniable benefit to categories in the url and that’s SEO. Google takes into account what words are in the URL for everything on your site. Given all other factors being equal, a site with the search term in the URL will score higher than one without it in.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Random string in category URL’s return valid pages’ is closed to new replies.