使用 symfony 1.4 而不更改 apache 配置
是否可以在不更改apache配置文件的情况下将/web目录设置为webroot?
我尝试使用以下 .htaccess 代码,但如果我转到 localhost/module/,它会显示 404 错误。但是如果我转到 localhost/web/module/ 那么一切都会正常。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule sf/(.*) lib/vendor/symfony/data/web/sf/$1 [L]
RewriteRule ^$ web/ [L]
RewriteRule (.*) web/$1 [L]
</IfModule>
Is it possible to set the /web directory as webroot without changing apache configuration file?
I tried using the following .htaccess code, but if i go to localhost/module/, it displays 404 error. But if i go to localhost/web/module/ then everything works.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule sf/(.*) lib/vendor/symfony/data/web/sf/$1 [L]
RewriteRule ^$ web/ [L]
RewriteRule (.*) web/$1 [L]
</IfModule>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我确实喜欢在根目录上这样做:
并编辑 web/.htaccess 取消注释“RewriteBase /”行。
这使得所有 mysite.com/aaaa/bbbb 都像 mysite.com/web/aaaa/bbbb 一样工作
i do like this on the root :
And edit web/.htaccess uncommented the 'RewriteBase /' line.
this make all the mysite.com/aaaa/bbbb works like mysite.com/web/aaaa/bbbb
简短的回答:不。
长一点:你必须编辑 apache 配置,至少授予它访问 web/ 目录的权限,所以即使你将你的 web 文件夹符号链接到 /var/www,它也不会工作。
Short answer: no.
Bit longer: you will have to edit the apache config at least to give it permission to access the web/ directory, so even if you symlink your web folder to /var/www, it will not work.
这与我的问题非常相似 虚拟主机上的 Symfony(文档根问题)。
这是我在项目根目录中的 .htaccess :
这解决了我的问题,但 symfony 尝试从文档根生成每个 url(例如使用 url_for ),而不是 url就像
domain.com/my-article
它生成domain.com/web/my-article
。我必须稍微修改我的
PatternRouting
类,以删除每个 url 中的/web
前缀。我认为这不是最好的解决方案,但它确实有效。另外,如果我想访问后端应用程序,我必须始终调用
/web/backend.php/
因为我不想在.htaccess
中有这么多重写规则。如果您想查看我的扩展
PatternRouting
类源代码,我会将其粘贴到此处。This is quiet similar to my question Symfony on virtual host (document root problem).
This is my
.htaccess
in the project root directory:This solved my problem but symfony tries to generate every url (eg. using
url_for
) from the document root so instead of url likedomain.com/my-article
it generatesdomain.com/web/my-article
.I had to slightly modify my
PatternRouting
class to trim the/web
prefix from each url. I think this is not the best solution but it works.Also if I want to access backend application I have to call always
/web/backend.php/
because I don't want to have so many rewrite rules in the.htaccess
.If you want to see my extended
PatternRouting
class source code I'll paste it here.是的,这是可能的。将所有内容从 web/ 向上复制到文档根目录。编辑index.php以反映这样一个事实:它包含的所有内容现在比以前更接近其当前目录一级(少一级../)。您无需编辑任何其他 Symfony 文件。
Yes, it is possible. Copy everything from web/ up a level to your document root. Edit index.php to reflect the fact that everything it includes is now one level closer to its current directory than it used to be (one less ../). You won't have to edit a single other Symfony file.