WordPress Anti-Pattern: Don’t Remove Trailing Slashes in URLs

I’ve had an unusual burst of inbound links to this site lately, and it just occurred to me last night that there are no visible trackbacks or pingbacks.

Hmmm. After temporarily changing themes, temporarily disabling plug-ins that might interfere with trackbacks and comments such as Akismet (which is absolutely wonderful, BTW!) and No Self Pings, I eventually stumbled upon the real cause:

My custom permalink structure lacked a trailing slash.

I turned on trailing slashes (i.e. back to the traditional year/month/post-name pattern), and life is good. It would have been nice if The Google had known about this, or if WP had contained a warning to that effect. Since it didn’t, I’ll share it here to save the next person some pain.

So, to be clear: Don’t do this:

Do this instead:

(These screen shots are from WP 2.6.5 under Settings > Permalinks.)

5 thoughts on “WordPress Anti-Pattern: Don’t Remove Trailing Slashes in URLs

  1. Claude

    It’s a bad idea to leave out a trailing slash for directories because it forces a redirect (HTTP status code 301), which adds a delay to the user’s experience. This could be what you identified as “an unusual burst of inbound links.”

    See Avoid Redirects here.

    Reply
  2. Eric

    Understood, but you’ve actually hit on the key misconception I had. I never thought of the individual post page as a directory. And there’s precedent for that: Look at the screen shots I posted above, specifically the “Numeric” version. There’s no trailing slash in “/archives/123″.

    By “unusual burst of inbound links,” I meant actual, valid inbound links from other sites, as indicated by the Google Blog Search in the Dashboard. So there really are pingbacks that are missing because I had a faulty URL scheme.

    Reply
  3. Poe Jea

    What exactly is the problem? The lack of the last slash makes it appear as if the site was linked to too many times? (i.e. a user on some other site clicked on the link like 10 times?

    What do we do if we MUST have the link with no slash at the end? I really hate the slash and want it off so it will look better.

    Thanks!

    Reply
  4. Eric

    @Poe: The problem is that WP constructs an invalid trackback URL, so your trackbacks get silently dropped on the floor.

    I don’t particularly care for the trailing slash either, but it seems like you have to decide between that and having trackbacks.

    (I’m not part of the WP development team; I’m just reporting what I’ve found from my own experience.)

    Reply

Leave a Reply