虚拟主机上的 Symfony(文档根问题)

Symfony on virtual host (document root problem)(虚拟主机上的 Symfony(文档根问题))
本文介绍了虚拟主机上的 Symfony(文档根问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在 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(文档根问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)