当 Rails 应用程序位于另一个 Rails 内部时如何配置 .htaccess?公共文件夹?

发布于 2024-10-16 20:54:46 字数 1171 浏览 1 评论 0原文

我的共享主机服务器上运行有一个 Rails 应用程序,并且 public_html 映射到 ~/rails_apps/app1/public。 这样做是为了让 www.mydomain.com 启动 app1。正如所料,.htaccess 是这样的

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

这里有一个新的 Rails app2,我想通过 www.mydomain.com/app2 访问它,

我创建了 ~/rails_apps/app2,并创建了指向那里的符号链接 public_html/app2 (该符号链接实际上是 ~/rails_apps/app1/public/app2)。

这个app2还需要dispatch.fcgi来启动,因此app2/public/.htaccess具有与上面相同的RewriteRules。

问题是,当我访问 www.mydomain.com/app2/hello 时,我的第一个 app1 正在接收请求,但失败了。我读这条规则是“文件/app2/hello不存在,将其发送到dispatch.fcgi进行处理”。

因此,我尝试在 app1/public 中设置附加规则,

RewriteCond %{REQUEST_URI} ^/app2/.*
RewriteRule ^(.*)$ /app2/dispatch.fcgi [L]

我的 app2 现在正在获取请求,但它尝试处理 /app2/hello ,但由于没有 /app2 ,该规则失败了code> 在我的路线中定义。它只需要接收 /hello

我还尝试将 RewriteBase /app2 放在上一段中的规则之前,但似乎没有任何区别。我还需要将 RewriteBase / 放在原始 app1 RewriteRule 之前,否则 app1 会中断。 (真诚地,我不知道是否允许多个 RewriteBase)

有什么想法可以解决我的问题吗?

I have a rails application running on my shared host server and the public_html is mapped to ~/rails_apps/app1/public.
This was done so www.mydomain.com launches app1. As expected, the .htaccess is like this

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Here comes a new rails app2, and I want to access it through www.mydomain.com/app2

I created ~/rails_apps/app2, and created the symlink public_html/app2 pointing there (the symlink is actually ~/rails_apps/app1/public/app2).

This app2 also needs the dispatch.fcgi to launch, so the app2/public/.htaccess has the same RewriteRules as above.

The problem is that when I access www.mydomain.com/app2/hello, my first app1 is receiving the request and it's failing. I'm reading this rule as "File /app2/hello doesn't exist, send it to dispatch.fcgi for processing".

So, I tried setting up an additional rule in app1/public

RewriteCond %{REQUEST_URI} ^/app2/.*
RewriteRule ^(.*)$ /app2/dispatch.fcgi [L]

My app2 is now getting the request, but it tries to process /app2/hello which fails since there is no /app2 defined in my routes. It needs to receive just /hello.

I also tried putting RewriteBase /app2 just before the rules in the above paragraph, but it didn't seem to make any difference. I also needed to put RewriteBase / before the original app1 RewriteRule, otherwise app1 breaks. (sincerely, I don't know if more than one RewriteBase is allowed)

Any ideas how to solve my problem?

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

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

发布评论

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

评论(1

傻比既视感 2024-10-23 20:54:46

调整 /app2 路由子目录尝试添加

config.action_controller.relative_url_root = '/app2'

到您的 environmet.rb (生产)...

希望这可以帮助

to adjust the /app2 routes subdirectory try to add

config.action_controller.relative_url_root = '/app2'

to your environmet.rb (production) ...

hope this could help

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