SEO issue with urls
In Kirby there is no built in redirect from for example
to
That might be an SEO issue with duplicate content and splitting the link power between the two. It’s not even good for users, because they don’t know which of the two adresses that are the correct one.
Redirect ending slash
I built a plugin that solved the problem with a redirect from the slash version to the no slash version. It does not redirect when in the panel, because that would make it fail.
<?php
redirect_ending_slash();
function redirect_ending_slash() {
if( is_ending_slash() && ! is_using_panel() && ! is_home() ) {
go( get_unslashed_url() );
}
}
function is_home() {
if( $_SERVER['REQUEST_URI'] === '/' ) return true;
}
function is_ending_slash() {
if( substr( $_SERVER['REQUEST_URI'], -1 ) === '/' ) return true;
}
function is_using_panel() {
if( substr( $_SERVER['REQUEST_URI'], 0, 6 ) === '/panel' ) return true;
}
function get_unslashed_url() {
return url() . substr( $_SERVER['REQUEST_URI'], 0, -1 );
}
Installation
- Create a folder in the plugins folder called
redirect-ending-slash
- Create the php file
redirect-ending-slash.php
. - Copy paste the code above into the php file.
- Done!
If panel folder has moved
If you move your panel folder around you need to change the plugin a little bit.
Issue with the $page object
Because of the issue below I could not use the $page
object to get the url contents. Instead $_SERVER
is used. Might be a little bit faster this way.
http://forum.getkirby.com/t/functions-unable-to-load-the-page-object/1081/7