Giter Club home page Giter Club logo

rack-seo_redirect's Introduction

Rack::SeoRedirect

Rack middleware for making non-www to www (and conversely) redirects and removing trailing slash in urls. Use it if you can not edit Nginx or Apache rewrite rules.

Installation

Add this line to your application's Gemfile:

gem 'rack-seo_redirect'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rack-seo_redirect

Usage

With any Rack application

# config.ru
require 'rack/seo_redirect'
use Rack::SeoRedirect::Www
use Rack::SeoRedirect::TrailingSlash
run MyApp

With Rails

Insert to the top of the Rails middleware stack:

# application.rb
config.middleware.insert 0, Rack::SeoRedirect::Www
config.middleware.insert 0, Rack::SeoRedirect::TrailingSlash

Customization

Rack::SeoRedirect::Www

Your can pass true or false as a parameter to Www middleware. This indicates either you need www in your url or not.

For non-www to www redirect use:

use Rack::SeoRedirect::Www, true

For www to non-www redirect use:

use Rack::SeoRedirect::Www, false

Default is false (www to non-www).

Rack::SeoRedirect::TrailingSlash

Your can pass true or false as a parameter to TrailingSlash middleware. This indicates either you need / in the end of your url or not.

For adding / to the end of urls use:

use Rack::SeoRedirect::TrailingSlash, true

For removing / from the end of urls use:

use Rack::SeoRedirect::TrailingSlash, false

Default is false (removing trailing slash).

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

rack-seo_redirect's People

Contributors

michaelkhabarov avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

merqlove dcalixto

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.