我们有一个土耳其网站,一些旧链接被某些搜索引擎抓取。这些链接似乎格式不正确或无法处理,因此导致
但是在服务器上我们会得到一个
在两种情况下,我们都希望重定向到一个“未找到页面”的页面。
我已经尝试过在
但是它们都没有起作用。
我希望有人遇到了同样的问题并已经解决了它。感谢您提前的回答。
编辑:
一个示例问题的URL是
终端输出:
ActionController::BadRequest
错误。在本地机器上使用 development env
会导致返回带有 ActionController::BadRequest
的 Rails 错误页面。但是在服务器上我们会得到一个
500 server error
。这个问题在其他几个页面上进行了讨论,例如这里。但是没有任何解决方案管用。在两种情况下,我们都希望重定向到一个“未找到页面”的页面。
我已经尝试过在
ApplicationController
中使用 rescue_from ActionController::BadRequest
和 rescue_from ActionController::RoutingError
,因为在前面提到的文章中,他们说 BadRequest
会变成 RoutingError
。但是它们都没有起作用。
我希望有人遇到了同样的问题并已经解决了它。感谢您提前的回答。
编辑:
一个示例问题的URL是
http://localhost:3000/Di%c5%ef%bf%bd-f%c4%b1r%c3%a7as%c4%b1
。终端输出:
ActionController::BadRequest (ActionController::BadRequest):
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:37:in `block in call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:33:in `each'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:33:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
newrelic_rpm (3.6.4.122) lib/new_relic/rack/error_collector.rb:12:in `call'
newrelic_rpm (3.6.4.122) lib/new_relic/rack/agent_hooks.rb:22:in `call'
newrelic_rpm (3.6.4.122) lib/new_relic/rack/browser_monitoring.rb:16:in `call'
newrelic_rpm (3.6.4.122) lib/new_relic/rack/developer_mode.rb:28:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__4278100521352222029__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
rollbar (0.11.7) lib/rollbar/middleware/rails/show_exceptions.rb:19:in `call_with_rollbar'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
puma (2.6.0) lib/puma/server.rb:486:in `handle_request'
puma (2.6.0) lib/puma/server.rb:357:in `process_client'
puma (2.6.0) lib/puma/server.rb:250:in `block in run'
puma (2.6.0) lib/puma/thread_pool.rb:92:in `call'
puma (2.6.0) lib/puma/thread_pool.rb:92:in `block in spawn_thread'
最好的祝愿