Change redirection of old content (.html / .php etc.) to Ruby on Rails

I switched to Ruby on Rails, and my current problem is to redirect old type content XXX/dummy.htmlor XXX/dummy.phpto RoR.

What exactly is the best solution for

  • isolated content ( XXX/onlyinstance.html)
  • which has an internal structure such as XXX/dummy1.html,XXX/dummy2.html

http://guides.rubyonrails.org/routing.html does not explain how to migrate old content.

Note. Changing old links is NOT an option. Website hosted, this is not my own server. Since the domain has not changed, a solution to redirect it does not seem to be necessary ... there should be a better solution.

EDIT: I found out that the best solution actually redirects it as described in the narrative.

So add the .htaccess file to the shared directory and write

RewriteEngine to
Redirect Permanent /XXX.php http: // XYZ / XXX

For some reason, RoR did not accept the redirect to route.rb ... while.html / .xml everything is going well, .php is not working. I did not find out why. Because weppos answer was the best, I will reward him with a 50-point award, but since the other answers are valid, too, I will promote them. Thanks to everyone.

+3
source share
3 answers

You can do this in several ways.

The best and most efficient way is to use your web server with an interface. You can easily configure some configurations to redirect all old URLs to new ones.

Apache mod_alias mod_rewrite.

Redirect /XXX/onlyinstance.html /new/path
RedirectMatch Λ†/XXX/dummy([\d])+\.html$ /new/path/$1

, Ruby.

/ , Rails. , , , /.

class Redirector
  def self.call(env)
    if env["PATH_INFO"] =~ %r{XXX/onlyinstance\.html}
      [301, {"Content-Type" => "text/html", "Location" => "http://host/new/path/"}, "Redirecting"]
    else
      [404, {"Content-Type" => "text/html"}, "Not Found"]
    end
  end
end

Rack plugin, Redirect, DLS Rack.

. , routes.rb, URL- .

. -www URL- Rails

+4

? URL- RoR. , HTTP 301. . http://en.wikipedia.org/wiki/HTTP_301:

HTTP- 301 .

HTTP-.

+2

, Rails RESTful ( , , ). , php, , , .. , Model, Controller .

HTML, , . , , .

, map.resource config/routes.rb. RESTful . -, Rails (WEBrick), script/server. , , , WEBrick .

I suggest you first write a basic (blog) application with Rails, see here . So you see which parts use Rails and how you can use them.

After that, you will be able to identify these parts in your PHP and bbetter solution, capable of converting your pages. At least I followed this approach when I started using / converting Rails from PHP.

+2
source

Source: https://habr.com/ru/post/1728449/


All Articles