【发布时间】:2011-06-07 00:51:32
【问题描述】:
我有一个大问题(即使是我的服务器管理员似乎也很难解决)。
我使用我的 cpanel (11.25.0-STABLE) 创建了一个新的 ruby on rails 应用程序,当访问其原始 uri(带有端口号)时,它可以正常工作。
为了使该 uri 更“用户友好”,我创建了一个重写来访问我的 RoR 应用程序而不显示端口号。
我重写的 uri 的 .htaccess 内容
RewriteEngine on
RewriteCond %{HTTP_HOST} ^greendeers.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.greendeers.com$
RewriteRule ^.*$ "http\:\/\/127\.0\.0\.1\:12001%{REQUEST_URI}" [P,QSA,L]
app/controllers/helloworld_controller.rb
class HelloworldController < ApplicationController
def index
end
end
app/views/layouts/helloworld.html.erb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= controller.controller_name %>: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= notice %></p>
<%= yield %>
</body>
</html>
app/views/helloworld/index.html.erb
<h1>HELLO WORLD</h1>
第一个页面(由 RoR 创建的原始页面)在两个 uri 上都可以正常工作,但是当访问我的一个控制器时,不会呈现 html,而是显示 html 代码。
http://www.greendeers.com/helloworld
此页面使用原始 uri(同上,端口号:12001)按预期呈现
访问两个 uri 时,我的日志显示相同的内容:
处理 HelloworldController#index (for [My ip address] at 2010-07-10 02:53:20) [GET]
在 layouts/helloworld 中渲染模板
渲染 helloworld/index
在 1 毫秒内完成(查看:1,DB:0)| 200 好 [http://greendeers.com/helloworld]
你知道如何解决它吗?
抱歉,我目前每篇帖子只能发布一个链接:/
【问题讨论】:
标签: html ruby-on-rails url-rewriting rendering cpanel