虚拟主机上的Symfony(文档根目录问题) [英] Symfony on virtual host (document root problem)

查看:84
本文介绍了虚拟主机上的Symfony(文档根目录问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Symfony和本地主机(XAMPP)上开发应用程序,我想模拟与Web服务器上相同的条件.

I'm developing an application in Symfony and on localhost (XAMPP) I want to simulate the same conditions as on the webserver.

Web服务器的配置如下:

The web server is configured as follows:

/www   => mydomain.com
/foo   => foo.mydomain.com
/bar   => bar.mydomain.com
...

我将把我的Symfony应用程序放入/www目录中,这样就可以了:

I'm going to put my Symfony application into /www direcotry so there'll be:

/www
/www/apps
/www/apps/frontend
/www/apps/frontend/...
/www/apps/backend
/www/apps/backend/...
/www/cache
/www/config
... and so on...
/www/web

问题是文档根目录仍然设置为/www目录,但是Symfony希望它在/www/web中.
如果我拨打http://mydomain.com/web当然可以,但是我想您知道这是一种安静的愚蠢解决方案.

The thing is that the document root is still set to the /www directory but Symfony expects it in the /www/web.
Of course it will work if I call http://mydomain.com/web but I guess you understand this is quiet stupid solution.

所以我的问题是:有什么方法可以使用.htaccess或其他方法更改/绕过默认文档根目录设置?

So my question is: Is there any way how can I change/bypass the default document root setting using .htaccess or whatever?

我已解决.

推荐答案

我对Symfony不太了解,但是/web应该是文档的根目录.出于安全原因,所有其他目录都应位于文档根目录之外,并避免使用URL中的/web部分.看来您已经知道了.

I don't know much about Symfony but /web is supposed to be the document root. All the other directories should be outside the document root for security reasons for one, and to avoid the /web part in the URL for another. But it looks like you already know that.

如果您可以编辑Web服务器的配置,请尝试反映该配置并将DocumentRoot设置为Web目录.

If you can edit the web server's configuration, try to reflect that and set DocumentRoot to the web directory.

如果不能这样做:无法更改.htaccess文件中的DocumentRoot,但是可以重写所有请求,以便它们使用mod_rewrite在内部进入/web.这很麻烦,但是如果您不影响DocumentRoot,则可能是最好的解决方案.

If you can't do that: It's not possible to change the DocumentRoot in a .htaccess file but it is possible to rewrite all requests so they go to /web internally using mod_rewrite. It's kludgy, but probably the best solution if you can't influence DocumentRoot.

我不是mod_rewrite专家,所以我无法提供示例(我必须先对其进行测试,并且现在无法进行此操作),但是我敢肯定有人会.也许在您的问题中添加mod_rewrite标签.

I'm not a mod_rewrite guru so I can't provide an example (I would have to test it first and I can't do that right now) but I'm sure somebody will. Maybe add the mod_rewrite tag to your question.

更新:未经测试,但应该有效.放入/www中的.htaccess文件:

Update: Untested but should work. Put into a .htaccess file in /www:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/web/ 
RewriteRule .* /web/%1 [QSA]

然后,您需要将配置文件更改为使用http://www.domain.com/而不是http://www.domain.com/web/.

you would then need to change your configuration files to use http://www.domain.com/ instead of http://www.domain.com/web/ of course.

我不能说这是否会干扰Symfony端的任何其他.htaccess规则-您必须尝试一下.

I can't say whether that interferes with any other .htaccess rules on the Symfony end - you'd have to try out.

这篇关于虚拟主机上的Symfony(文档根目录问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆