URLs in Catalyst Apps

Google along with many other search engines has a habit of treating URLs differently if they end with a trailing-slash or not. How much this actually harms your SEO is questionable, but I prefer things consistent.

URLs in Catalyst Apps

The following URLs are seen as completely different:

http://www.myselfequalsshift.com/blog/urls-in-catalyst-apps
http://www.myselfequalsshift.com/blog/urls-in-catalyst-apps/

Most of the time these 2 requests will result in the same place, and Google will see duplicate content.

To protect against this, override the following methods in MyApp.pm...

sub uri_for
{
    my $c = shift;
    my $uri = $c->next::method( @_ );
    $uri->path( $uri->path . '/' ) if $uri->path !~ m:/$:;
    return $uri;
}

sub uri_for_action
{
    my $c = shift;
    my $uri = $c->next::method( @_ );
    $uri->path( $uri->path . '/' ) if $uri->path !~ m:/$:;
    return $uri;
}

Hostless or Relative URLs

By default Catalyst will create fully qualified URLs which I'm not overly keen on, so to enable hostless, or even relative URLs, list SmartURI in your MyApp.pm plugins...

use Catalyst qw/
    ...
    SmartURI
    ...
/;

And modify your config:

<Plugin::SmartURI>
    disposition     host-header
    uri_class       URI::SmartURI
</Plugin::SmartURI>

Now in your templates:

<a href="[% c.uri_for_action( '/mycontroller/myaction' ).hostless %]">some link</a>
Leave Comment
Yay! You've decided to leave a comment. That's fantastic! Please keep in mind that comments are moderated. So, please do not use a spammy keyword or a domain as your name, or it will be deleted. Let's have a personal and meaningful conversation instead. Thanks for dropping by!