【发布时间】:2011-10-14 23:36:27
【问题描述】:
我在我的routing.yml 中配置了这种模式:
/{customer}/{site}/content/{id}.{format}
现在我想省略/{customer}/{site} 部分并用重写规则重写它。
Symfony 已经有一个带有重写规则的.htaccess。我修改为
RewriteRule ^(.*)$ app_dev.php/foo/bar/$1 [QSA,L]
但是当我将浏览器指向 http://localhost/content/42.html 时,我得到了这个异常:
No route found for "GET /content/42.html"
我摆弄了一下,发现为什么会出现这个问题:Symfony 使用 _SERVER['REQUEST_URI'] 变量来解析请求,但是当你使用 mod_rewrite 时,这个 var 中的 URL 不是预期的 /foo/bar/content/42.html 而是 @987654330 @。
我可以用我自己的替换 app_dev.php 并覆盖 REQUEST_URI 但我不想破解 Symfony。
编辑:
从路由配置中删除 /{customer}/{site} 部分不是解决方案,因为我正在处理多客户/多站点应用程序,我想通过 URL 隐藏这些部分,以便我可以将浏览器指向 www.my-fancy-site.com 和apache 将此 URL 重写为 /foo/bar/content/42.html。
【问题讨论】:
标签: mod-rewrite symfony