Ruby on Rails .htaccess 问题

发布于 2024-09-18 13:26:52 字数 578 浏览 2 评论 0原文

当我在 Apache 上运行新创建的 Rails 应用程序时,我只能访问它的默认首页(标准 app/public/index.html)文件。当我尝试通过 URI 运行自定义方法时,我发现页面未找到。所以我猜测我的 .htaccess 有问题。我必须为每个控制器“打开”它吗?

RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^main(.*) "http\:\/\/127\.0\.0\.1\:12005\/$1" [P,L]

编辑: 我正在添加杂种日志

Error calling Dispatcher.dispatch #<NoMethodError: private method `split' called for nil:NilClass>
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/cgi_process.rb:52:in `dispatch_cgi'

When I run newly created Rails application on Apache, I can only access it's default front page ( standard app/public/index.html) file. When I try to run custom method via URI I get page not found. So I'm guessing that something is wrong with my .htaccess. Do I have to "open" it for every controller?

RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^main(.*) "http\:\/\/127\.0\.0\.1\:12005\/$1" [P,L]

Edit:
I'm adding mongrel log

Error calling Dispatcher.dispatch #<NoMethodError: private method `split' called for nil:NilClass>
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/cgi_process.rb:52:in `dispatch_cgi'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花桑 2024-09-25 13:26:52

问题实际上是在 Rails 2.3.x 和 Mongrel 之间,而不是 .htaccess 之间

进行了讨论&在 https://rails 找到了解决方案(通过猴子修补) .lighthouseapp.com/projects/8994/tickets/4690#ticket-4690-43

The problem is actually between Rails 2.3.x and Mongrel, instead of .htaccess

It was discussed & a solution was found (by monkey patching) at https://rails.lighthouseapp.com/projects/8994/tickets/4690#ticket-4690-43

箜明 2024-09-25 13:26:52

呵呵,Ruby on Rails 不关心 .htaccess。欢迎来到 MVC 世界 :-) 最有可能的是,您没有在 Rails 内定义任何路线。或者你没有使用乘客。

Heh, Ruby on Rails does not care about .htaccess. Welcome to the MVC world :-) Most likely, you didn't define any routes inside rails. Or you're not using passenger.

ˉ厌 2024-09-25 13:26:52

首先,您可以将前两个规则更改为:

RewriteCond %{HTTP_HOST} ^(www\.)?example.com$

另外,最后一个规则不需要所有这些反斜杠,并且由于 $1 之前有一个斜杠,因此您在 ^main(.*) 中也应该有一个斜杠:

RewriteRule ^main/(.*)$ "http://127.0.0.1:12005/$1" [P,L]

尝试一下作品。我不确定 P 做了什么以及它是如何工作的,所以如果问题在那里我无法帮助你..

First of all, you can change the first two rules to:

RewriteCond %{HTTP_HOST} ^(www\.)?example.com$

Also, the last rule doesn't need all those backslashes, and since there's a slash before your $1 you should have one in ^main(.*) too:

RewriteRule ^main/(.*)$ "http://127.0.0.1:12005/$1" [P,L]

Try if that works. i'm not sure what P does and how that works, so if the problem is in there I can't help you..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文