WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#3899 closed defect (bug) (fixed)

Function user_trailingslashit breaks .html permalinks

Reported by: 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)

comment:1 markjaquith7 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.

comment:2 johnbillion7 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?

comment:3 markjaquith7 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.

comment:4 lunabyte7 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.

comment:5 markjaquith7 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.

comment:6 markjaquith7 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

comment:7 markjaquith7 years ago

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

comment:8 markjaquith7 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);

comment:9 markjaquith7 years ago

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

comment:10 markjaquith7 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.

comment:11 lunabyte7 years ago

Awesome, and much appreciated Mark.

Note: See TracTickets for help on using tickets.