问题描述
我想在生产环境中访问我的 symfony 应用程序 (http://www.sample.com/amateur1/web/app.php) 来自这个 url http://www.sample.com/amateur1.
I want to access my symfony app in production env (http://www.sample.com/amateur1/web/app.php) from this url http://www.sample.com/amateur1.
为此,我将 .htacces 文件移至 http://www.sample.com/amateur1/.htaccess 包含以下内容:
To do that I moved the .htacces file to http://www.sample.com/amateur1/.htaccess with this contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
但是当我去 http://www.sample.com/amateur1 显示 404错误,prod.log 未写入.
But when I go to http://www.sample.com/amateur1 shows a 404 Error, and prod.log isn't written.
我也使用了 RewriteBase/amateur1/web/
因为我不知道 RewriteBase 路径是否相对于服务器的 DocumentRoot, 或者从 .htaccess 文件所在的路径.由于这个答案,还尝试将 /amateur1
和 /amateur1/
作为 RewriteBase Symfony2:如何在子目录(Apache)中部署
I also used RewriteBase /amateur1/web/
because I don't know If RewriteBase path is relative to the DocumentRoot of the server, Or from the path where the .htaccess file is located. Also tried /amateur1
and /amateur1/
as RewriteBase due to this answer Symfony2: How to deploy in subdirectory (Apache)
通过三个尝试,异常页面显示为无样式,并且未加载任何图像.但是后来我在 prod.log 文件中收到以下错误:
With the three try's, The Exceptions page appears unstyled, and not loading any image. But then I get the following error in prod.log file:
[2013-02-15 02:06:47] request.ERROR: SymfonyComponentHttpKernelExceptionNotFoundHttpException: No route found for "GET /amateur1/" (uncaught exception) at /home/u105859802/public_html/amateur1/app/cache/prod/classes.php line 5121 [] []
我做错了什么?
推荐答案
在你的配置中,apache 使用 public_html
作为文档根
In your configuration, apache uses public_html
as the document root
如果 Symfony2 安装在 /home/u105859802/public_html/amateur1
目录下,Symfony 公共目录是 /home/u105859802/public_html/amateur1/web/
If Symfony2 is installed in directory /home/u105859802/public_html/amateur1
, the Symfony public directory to serve is /home/u105859802/public_html/amateur1/web/
你应该使用
RewriteBase /amateur1/web/
但要注意,它不安全
您必须保护您的 symfony 目录!(配置可访问)
为什么不尝试将 symfony 文件移动到您的私人区域?
您可以将 Symfony 网络目录重命名为 public_html
Why don't you try moving your symfony files in your private area ?
You can rename the Symfony web directory to public_html
所以,我的推荐结构如下所示:
So, my recommendation structure looks like below :
- /home/u105859802/
- 供应商
- 源代码
- 应用
- 斌
- public_html(symfony2 中默认为 web)
- /home/u105859802/
- vendor
- src
- app
- bin
- public_html (web by default in symfony2) <- the only public directory
这篇关于如何在共享主机上部署 Symfony2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!