-1

I have a Rails application and it is working great. For some specific page I would like to redirect it to some other page when a user requests that page, but what I want is to do a redirection outside Rails code, so the settings ,at the end, would have to be outside rails code itself. There could be a htaccess file to modify as an outside file to redirect to some other page, but I haven't done that so far with rails.

So, the questions is - Is that possible?

Aleks
  • 4,866
  • 3
  • 38
  • 69
  • What is "to do a redirection outside Rails code"? – Sully Feb 25 '14 at 12:38
  • I don't want to make any changes in the Rails code itself to make a redirection. Is there a way to do that outside a Rails code? That is what I have meant – Aleks Feb 25 '14 at 12:40

2 Answers2

1

You need to handle the request before it hits Rails app. For example you can create a rewrite rule in a configuration of HTTP server you're using (nginx, apache, etc).

See these links:

If you don't have access to your server configuration (e.g. you're on Heroku) you can use refraction gem (https://github.com/joshsusser/refraction). It is a middleware, so in fact you're putting this redirection logic inside Rails, but at least it does not hit your controllers.

Community
  • 1
  • 1
Michał Szajbe
  • 8,830
  • 3
  • 33
  • 39
0

Rails allows for external URL's in redirect_to, so you can do something like:

redirect_to "http://www.example.com/interesting_page"

If that is what you were looking for.

zwippie
  • 15,050
  • 3
  • 39
  • 54
  • Thanks zwippie, but is there a way to define redirection rules outside rails application, like defining a `htaccess` or something like that on web-site that are using rails – Aleks Feb 25 '14 at 12:46