我正在 Symfony 和本地主机 (XAMPP) 上开发应用程序,我想模拟与网络服务器上相同的条件.
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
,但可以重写所有请求,以便它们转到 /web
在内部使用 mod_rewrite
.它很笨拙,但如果您不能影响 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(文档根问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!