justintadlock / breadcrumb-trail

Official home of the Breadcrumb Trail plugin for WordPress.
GNU General Public License v2.0
136 stars 61 forks source link

Trailing slash home URL #20

Closed justintadlock closed 7 years ago

justintadlock commented 8 years ago

Probably need to use user_trailingslashit() over the output of home_url().

See: https://github.com/justintadlock/hybrid-core/issues/127

fobHub commented 8 years ago

I guess it is not possible to use something else. The server is always looking for something that it can load (like /index.htm, /index.html or /index.php) behind the slash. This doesn`t work without a slash so that the server has to redirect the click in order to find something that it can load.

(Deciding to choose a www address or not is another thing and it has not to do anything with seo linking strategies. It just feels wrong for me to force redirects here.)

justintadlock commented 8 years ago

The trailing slash is handled via Settings > Permalinks. If you add one there, that's how WP decides where to add it. For example, I don't use a trailing slash at http://themehybrid.com.

That's where user_trailingslashit() comes into play. That function will decide to add/remove the trailing slash.

fobHub commented 8 years ago

Hmmm...? ;-) Firefox and Google Chrome don`t show the domain slash anymore. Are you sure you checked it out with Safari or Microsoft IE/Edge already? You can even check your domain on google.com and you will see they listed it with a slash (because there is nothing to read without it). Makes sense. I thought the trailingslash function is only good for deep links where you can choose unnatural links (without a slash) in order to reduce your folder structure depth if you like. (Some people have chosen to do that years ago for seo purposes. I used .html but will kick it out whenever I will find some time to refresh my own homepage. ;-) )

fobHub commented 8 years ago

Just to avoid speaking about different things here:

My suggestion was to add esc_url(home('/')) to the first breadcrumb trail to have a clean domain link without redirections here. Whenever I link to the front page (for example on logo links or footer links) I use clean links with a slash.

The function user_trailingslashit() should in my opinion better be used only for post or page links.

I mean "root is root". The root will always be a directory. So you can play with the other directories only.

May be this ressource explains it better than I do: https://googlewebmastercentral.blogspot.de/2010/04/to-slash-or-not-to-slash.html

justintadlock commented 8 years ago

Funny reading: :)

Rest assured that for your root URL specifically, http://example.com is equivalent to http://example.com/ and can’t be redirected even if you’re Chuck Norris.

justintadlock commented 8 years ago

I'm reading up on this. I'm fairly certain I won't add the slash as a default, but I'm open to hearing any ideas. A simple filter on home_url would probably be a good idea to make sure all instances of this are covered.

fobHub commented 8 years ago

Yes, the Chuck Norris part is a bit funny. I tried to find some more technical information for you but it is hard to find. What I mean is that for example your apache server has to find the files first before it can do anything with it that has to do with the project itself. Even if it just wants to find your .htaccess resp. your rewrite rules it has to jump into the directory first, to read it. While doing this it automatically adds a slash (if you didn`t link to it yourself). Especially if you have a lot of pages you can theoretically run into performance issues with some bots that try to crawl your domain. A redirect makes the things slower, a slash is the preferred method.

Okay. People are normally writing about harmonizing URLs only (making sure that you do not mix up links with slash and links without it). But if you dig deeper into Webmaster Central you should find recommendations for the slash variant nowadays. I found something here: https://productforums.google.com/forum/#!topic/webmasters/sHySlg9X3ZM .

fobHub commented 8 years ago

This is a ressource from Apache explaining why they use directory slashes by default: Apache 2.0: http://httpd.apache.org/docs/2.0/mod/mod_dir.html#directoryslash ... 2.4: https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directorycheckhandler .

justintadlock commented 8 years ago

I was on my tablet last night, so it was hard to post code. Obviously, you'll want this to be consistent for all links to your root page. The best way to make sure that is consistent is with something like this:

add_filter( 'home_url', 'my_home_url', 10, 2 );

function my_home_url( $url, $path ) {

    return ! $path ? trailingslashit( $url ) : $url;
}
fobHub commented 8 years ago

Hmmm... This solution looks interesting but will corrupt the function everywhere where it is used already to prepare some links for breadcrumb trails, template parts and plugin functions. Don`t you think so, too?

I mean, if you use it somewhere else like this already: echo esc_url( home_url() ); ?>/something/ you will get a double slash. Won`t you?

I think it is a bit too risky if I limit the home function to a less flexible slash version.

justintadlock commented 8 years ago

If someone is using esc_url( home_url() ); >/something/, they're using home_url() incorrectly.

Anyway, I was just pointing that out as a possible interim solution for you. We're getting a bit out of scope for the ticket though.

fobHub commented 8 years ago

Alright. Perhaps the example was a bit funny but can be the result of a quick and dirty search and replace for deprecated functions like bloginfo('url') which should be cleaned up anyway. ;-)

fobHub commented 8 years ago

The longer I think about your suggested function the better I feel with using it, may be even as a standard usage.

I reviewed the WP Core against the usage of home_url() and although it seems to be standard to use home_url('/') nowadays (even within the newest template) it doesn`t look 100% consistent in this point. (Long time story, I have to clean up things like this for about 10 years already.)

Well - consistency is a must, a minimum requirement for every homepage, when it comes to performance and seo requirements. It doesn`t make sense to let the server or even the search engines guess what you want. Your statement has to be absolutely clear in

Looks like a good idea to stop firefighting on single places and see what the next update will bring in. So 'yes' - it might be a very good idea to fix those things flat and bring in a manipulated home_url() function istead. Thanks very much! ;-)