問題描述
我正在 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(文檔根問題)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!