0

My goal is when user requests root (AND ONLY ROOT, other pages work fine) with something like:

http://domain.com/////
http://domain.com//////////////
http://domain.com//

app should 301 redirect user to one and only correct:

http://domain.com/

I'm using Webrick, rack-rewrite gem and planning to host it on Heroku. Please remember that i'm new in Rails.

UPDATE ======

Rails: redirect all unknown routes to root_url — this is totally different problem. They just redirect all unknown hosts to root. I have 404 working normally.

My problem is that any amount of slashes works as homepage and URL has all of those slashes. I'm doing it for SEO to get rid of duplicates of homepage. I want it to work like here: http://netpeak.ua (try "netpeak.ua////////", you will be redirected to "netpeak.ua").

UPDATE 2 - added content of routes.rb ======

Rails.application.routes.draw do

  resources :questions

  resources :feedbacks

  devise_for :users

  get '' => 'public#index'

  get '/agency' => 'public#about'
  get '/contact' => 'public#contact'
  get '/uslugi' => 'services#index'
  get '/portfolio' => 'projects#index'
  get '/uslugi/:id' => 'services#show'
  get '/portfolio/:id' => 'projects#show'

  resources :articles, param: :id
  resources :settings, as: 'home' #home so it doesn't go to another page

  namespace :admin do
    resources :articles, :users, :projects, :services, :feedbacks, :questions
    get '' => 'projects#index'
    get 'contact' => 'settings#contact'
    get 'feedback' => 'settings#feedback'
    get 'fininfo' => 'settings#fininfo'

    get 'calls' => 'settings#calls'
    get 'orders' => 'settings#orders'
    get 'letters' => 'settings#letters'
    get 'allquestions' => 'settings#allquestions'

    get 'projectsettings' => 'settings#projectsettings'
    get 'servicessettings' => 'settings#servicessettings'
    get 'aboutsettings' => 'settings#aboutsettings'
    get 'startpagesettings' => 'settings#startpagesettings'
    patch 'contact' => 'settings#update'
    patch 'feedback' => 'settings#update'
    patch 'fininfo' => 'settings#update'
    patch 'projectsettings' => 'settings#update'
    patch 'servicessettings' => 'settings#update'
    patch 'aboutsettings' => 'settings#update'
    patch 'startpagesettings' => 'settings#update'
  end

end
Community
  • 1
  • 1
golodenko
  • 83
  • 1
  • 8
  • Have you tested it is actually not happening already? – BroiSatse Oct 30 '14 at 00:39
  • Off course I Have tested. aeroplan.herokuapp/com — try is yourself. – golodenko Oct 30 '14 at 14:00
  • Could you show your routes - rails should redirect automatically. – BroiSatse Oct 30 '14 at 15:02
  • I've updated question with routes.rb content. – golodenko Oct 30 '14 at 18:52
  • The application you mentioned is working as expected. `➜ ~ curl -I http://aeroplan.herokuapp.com/agency/////////////` returns a `HTTP/1.1 301 Moved Permanently` to `Location: http://aeroplan.herokuapp.com/agency/` – Simone Carletti Oct 30 '14 at 20:39
  • Oh, you've been trying to access to /agency/ and that what i've fixed. PLEASE, EVERYBODY PAY ATTENTION HERE: My problem IS ONLY ROOT of website. Startpage with only slashes after .com Everything else works just fine. – golodenko Nov 02 '14 at 14:23

0 Answers0