如何确保 Symfony url_for() 包含 PHP 文件名?
我一直在努力在 IIS Web 服务器上设置我的 Symfony 项目,但它几乎可以正常工作。
但我仍然无法让漂亮的 URL 正常工作。当我使用我的开发环境时,url_for
生成类似于 .../frontend_dev.php/booking/create
的 URL,并且一切正常。但是,一旦我使用 prod 环境 url_for
就会生成类似于 .../booking/create
的 URL,这可能是由于重写设置问题而无法工作在 IIS 上。
我不想尝试在 IIS 上进行正确的重写 - 我已经对此进行了很长时间的研究,但已经放弃了。如果您有解决我的问题的灵丹妙药,那么我很想知道,但这并不是问题的真正含义。
我发现调用 .../index.php/booking/create
效果很好。因此,我只需确保 url_for 始终添加文件名即可解决我的问题。但我该怎么做呢?我认为它可能只是假设 index.php
,所以我制作了一个名为 frontend.php
的副本,但它仍然生成不错的 URL,但没有文件名。似乎如果是开发环境,它会添加该文件,但如果是生产环境,它会隐藏它。关于如何覆盖这个的任何想法?
I've been battling to set up my Symfony project on a IIS web server, but have got it pretty much working.
I still can't get the nice URLs working though. When I use my dev environment, url_for
generates URLs that look like .../frontend_dev.php/booking/create
and everything works fine. But as soon as I use the prod environment url_for
generates URLs that look like .../booking/create
, which don't work presumably because of problems with the rewrite setup on IIS.
I don't want to try and get the proper rewrite working on IIS - I've stuffed around with that for ages now and have given up. If you have a silver bullet to fix my problem then I'd love to know but that's not really what the question is about.
I've found that calling .../index.php/booking/create
works fine. Therefore I can fix my problem simply by ensuring that url_for
always adds the filename. But how can I do this? I thought it might be just assuming index.php
, so I made a copy called frontend.php
but it still generates nice URLs, without the filename. It seems that if it's the dev environment, it adds the file, but if it's the prod environment, it hides it. Any ideas on how to override this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
apps/appname/config/settings.yml
中,将no_script_name
设置为false
。请参阅 symfony 参考书。
In
apps/appname/config/settings.yml
, setno_script_name
tofalse
.See the symfony Reference Book.