当 Rails 应用程序位于另一个 Rails 内部时如何配置 .htaccess?公共文件夹?
我的共享主机服务器上运行有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调整 /app2 路由子目录尝试添加
到您的 environmet.rb (生产)...
希望这可以帮助
to adjust the /app2 routes subdirectory try to add
to your environmet.rb (production) ...
hope this could help