Make WordPress Core

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#3899 closed defect (bug) (fixed)

Function user_trailingslashit breaks .html permalinks

Reported by: lunabyte's profile lunabyte Owned by:
Milestone: 2.2 Priority: normal
Severity: major Version: 2.2
Component: Administration Keywords: permalink html canonical
Focuses: 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 (11)

#1 @markjaquith
18 years ago

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.

#2 @johnbillion
18 years ago

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?

#3 @markjaquith
18 years ago

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.

#4 @lunabyte
18 years ago

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.

#5 @markjaquith
18 years ago

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.

#6 @markjaquith
18 years ago

  • Resolution set to fixed
  • Status changed from new to closed

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

#7 @markjaquith
18 years ago

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

#8 @markjaquith
18 years ago

  • Keywords canonical added

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);

#9 @markjaquith
18 years ago

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

#10 @markjaquith
18 years ago

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.

#11 @lunabyte
18 years ago

Awesome, and much appreciated Mark.

Note: See TracTickets for help on using tickets.