Ticket #3899 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Function user_trailingslashit breaks .html permalinks

Reported by: lunabyte Assigned to: anonymous
Priority: normal Milestone: 2.2
Component: Administration Version: 2.2
Severity: major Keywords: permalink html canonical
Cc:

Description

After chasing tails with a missing trailing slash, I tracked it down to what the title says.

With an r4929 version of link-template.php, and r4887 of rewrite.php, if a user has a permalink structure that is similar to /%category%/%postname%.html they end up with missing trailing slashes on pages and categories.

Change History

03/03/07 08:46:19 changed by markjaquith

There's no way to determine that you want trailing slashes with that (strange, to say the least) permalink structure. You definitely don't want them on your individual permalinks.

03/03/07 20:15:43 changed by johnbillion

I'm guessing lunabyte is using that permalink structure so as not to break old permalinks on a site which has switched over from using static HTML pages to using WordPress, am I right?

03/04/07 18:21:04 changed by markjaquith

I've also seen people recommend it for mysterious SEO reasons. Something about search engines knowing the difference between a dynamic and a static page (rubbish, that).

We could put a filter on the function, so that people with such structures who want trailing slashes on everything but individual permalinks can just install a plugin.

03/08/07 06:05:54 changed by lunabyte

John would be correct. It's an older site that was well indexed was converted to WP, and has been maintained with WP since. Liked the clean look with %postname%.html as well, so kept it.

A filter would be fine Mark, or even a check box as an option to go all the way with it. Kind of a trivial issue, but might cause a lot of folks a little grief when the SE's have dup links with and without the trailing slash and they possibly take a hit for dup content.

03/10/07 00:04:54 changed by markjaquith

Regarding SEO and duplicate content, Matt and I have been working on some canonicalization code that would rectify that situation. Still, you may want your nice canonical URLs to have trailing slashes even though your permalink structure doesn't. Tricky to fix, but I'll give it a shot.

03/10/07 06:18:47 changed by markjaquith

  • status changed from new to closed.
  • resolution set to fixed.

(In [5019]) user_trailingslashit filter for users who sometimes want trailing slashes only on certain URL types. fixes #3899

03/10/07 06:25:38 changed by markjaquith

(In [5020]) new function: untrailingslashit(). fixes #3899

03/10/07 06:28:40 changed by markjaquith

  • keywords changed from permalink html to permalink html canonical.

Now plugins can filter on 'user_trailingslashit' which will pass along as a second param the type of URL being filtered. So for lunabyte, you'd do this in a plugin:

function lunabyte_trailingslashes($string, $type) {
	if ( 'single' == $type )
		return $string;
	else
		return trailingslashit($string);
}

add_filter('user_trailingslashit', 'lunabyte_trailingslashes', 10, 2);

03/10/07 08:32:59 changed by markjaquith

(In [5021]) Improvements to untrailingslashit() and trailingslashit(). props Jamie Talbot. fixes #3899

03/10/07 08:37:28 changed by markjaquith

untrailingslashit() now uses rtrim() instead of regex (thanks Jamie!). And now trailingslashit() calls untrailingslashit() then adds a slash, instead of checking for the existence of a trailing slash and conditionally adding one. Benefit:

$foo = trailingslashit('http://wordpress.org//');

Old result: http://wordpress.org//

New result: http://wordpress.org/

So use trailingslashit() when you want the string to have one (and only one) trailing slash, and use untrailingslashit() when you want the string to have no trailing slashes.

03/11/07 05:53:35 changed by lunabyte

Awesome, and much appreciated Mark.