Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

rack-canonical-header

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rack-canonical-header

bundlerRubygems
Version
1.0.3
Version published
Maintainers
1
Created
Source

rack-canonical-header

Inserts a canonical url with a predefined host to prevent search engines from crawling domains like herokuapp.com

Setup

git clone git@github.com:renuo/rack-canonical-header.git
cd rack-canonical-header
bin/setup

Installation

Add this line to your application's Gemfile:

gem 'rack-canonical-header'

And then execute bundle install

Usage

Set the CANONICAL_HOST env variable to the desired host (i.e. set it to the domain of your website like CANONICAL_HOST=example.com)

The gem will inject a header of the format Link: <http[s]://CANONICAL_HOST[/path]>; rel=canonical as soon as the env is present. The path and the scheme will be replaced with what was requested on the original domain.

Note that the gem does no redirects. Therefore, your non-canonical urls will still work if you access them directly. However, search engines will not list them.

Non-Rails frameworks

If you're using a framework which uses Rack (like Hanami) you have to require and insert the middleware Canonical::Middleware manually into the rack stack.

For example:

require 'rack/auth/basic'
require 'rack-canonical-header'

module Web
  class Application < Hanami::Application
    configure do
      middleware.use Canonical::Middleware
    end
  end
end

FAQs

Package last updated on 09 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts