remove trailing slash and redirect (SEO)
This commit is contained in:
parent
a5cd2290ea
commit
40530de8bb
@ -47,5 +47,6 @@ module Locomotive
|
||||
config.filter_parameters << :password
|
||||
|
||||
config.middleware.insert_after Rack::Lock, '::Locomotive::Middlewares::Fonts', :path => %r{^/fonts}
|
||||
config.middleware.insert_after Rack::Lock, '::Locomotive::Middlewares::SeoTrailingSlash'
|
||||
end
|
||||
end
|
||||
|
@ -33,7 +33,7 @@ unless Locomotive.engine?
|
||||
begin
|
||||
require 'rack/cache'
|
||||
Rails.application.middleware.insert_before 'Dragonfly::Middleware', 'Rack::Cache', {
|
||||
:verbose => true,
|
||||
:verbose => false,
|
||||
:metastore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
|
||||
:entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
|
||||
}
|
||||
|
4
doc/TODO
4
doc/TODO
@ -21,7 +21,9 @@ x contents permalink (UI)
|
||||
x BUG: has_one / has_many. Delete an author
|
||||
x bushido changes in the master
|
||||
? edit sidebar (inline editor). Unable to reset it
|
||||
- SEO: support and support/ should be 2 different pages. Remove trailing slash
|
||||
x SEO: support and support/ should be 2 different pages. Remove trailing slash
|
||||
- Httparty (issue #...)
|
||||
- Has_one => group by in the select
|
||||
|
||||
|
||||
BACKLOG:
|
||||
|
@ -35,6 +35,7 @@ module Locomotive
|
||||
|
||||
initializer "serving fonts" do |app|
|
||||
app.middleware.insert_after Rack::Lock, '::Locomotive::Middlewares::Fonts', :path => %r{^/fonts}
|
||||
app.middleware.insert_after Rack::Lock, '::Locomotive::Middlewares::SeoTrailingSlash'
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1 +1,2 @@
|
||||
require 'locomotive/middlewares/fonts'
|
||||
require 'locomotive/middlewares/seo_trailing_slash'
|
24
lib/locomotive/middlewares/seo_trailing_slash.rb
Normal file
24
lib/locomotive/middlewares/seo_trailing_slash.rb
Normal file
@ -0,0 +1,24 @@
|
||||
module Locomotive
|
||||
module Middlewares
|
||||
class SeoTrailingSlash
|
||||
|
||||
def initialize(app, opts = {})
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
path = env['PATH_INFO']
|
||||
|
||||
if !path.starts_with('/admin/') && (match = path.match(%r{(.+)/$}))
|
||||
response = Rack::Response.new
|
||||
response.redirect(match[1], 301) # moved permanently
|
||||
response.finish
|
||||
response.to_a
|
||||
else
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -85,7 +85,7 @@ describe 'Locomotive rendering system' do
|
||||
@controller.send(:locomotive_page).should be_true
|
||||
end
|
||||
|
||||
context 'redirect page' do
|
||||
context 'redirect' do
|
||||
|
||||
before(:each) do
|
||||
@page.redirect = true
|
||||
|
25
spec/requests/seo_trailing_slash_spec.rb
Normal file
25
spec/requests/seo_trailing_slash_spec.rb
Normal file
@ -0,0 +1,25 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Locomotive::Middlewares::SeoTrailingSlash do
|
||||
|
||||
it 'does not process the "/" url' do
|
||||
get '/'
|
||||
response.status.should_not be(301)
|
||||
end
|
||||
|
||||
it 'does not process the "/admin/" url' do
|
||||
get '/admin/'
|
||||
response.status.should_not be(301)
|
||||
end
|
||||
|
||||
it 'does not process the "/admin/*" urls' do
|
||||
get '/admin/login'
|
||||
response.status.should_not be(301)
|
||||
end
|
||||
|
||||
it 'redirects to the url without the trailing slash' do
|
||||
get '/hello_world/'
|
||||
response.status.should be(301)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user