需要在 Zend Framework 上将 url /foo/index 重新路由到 index/foo
我需要在这里重新路由一个网址。我正在使用最终框架,需要在这里设置一些基本的静态页面。像隐私政策、广告等 - 但问题是我需要为这里的每个页面创建一个控制器。这不是什么大问题,但我想知道我是否可以将其设置为:
mysite.com/privacy/index
将被重新路由到
mysite.com/pages/privacy
可能听起来不是问题,但想知道
I need to reroute a url here. I'm using teh end framework and need to set up some basic static pages here. LIke privacy policy, advertise etc - however the problem is that I need to create a controller for each and every page here. Thats not much of an issue but I was wondering if its possibel for me to set it up so:
mysite.com/privacy/index
would be rerouted to
mysite.com/pages/privacy
Might sound like a non issue but would like to know
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于每个静态页面,您可以在 application.ini 中为其添加路由。例如,对于
mysite.com/privacy/index
,您可以执行以下操作:有关 ZF 中路由的更多信息,请参阅 ZF 的 手册。
希望这有帮助
For every static page, you can add a route for it in your application.ini. For example, for
mysite.com/privacy/index
you can do:More about routing in ZF is in the ZF's manual.
Hope this helps
根据我的经验,如果不是 100% 需要,我会强烈不鼓励创建自定义路由(带有产品关键字的 URL 或 CMS 生成的页面除外)。我们希望我们的电子商务解决方案拥有像
/about-us/
这样的漂亮网址,而不是/pages/about-us/
,但 PITA 需要添加更多功能,如你必须为每一个这样的事情添加新的路线。目前我们有大约 25 条定制路线。你永远无法判断这个 url 是什么 hack,因为像Producer/index 这样的标准 url 是从
Producers 之类的东西路由的。
如果您仍然想要它,请按照 Marcin 的回答:)
From my experience I would STRONGLY discourage creating custom routes if not 100% needed (exception be urls with keywords for products or CMS generated pages). We wanted to our ecommerce solution to have nice urls like
/about-us/
instead of/pages/about-us/
, but it's PITA to add any more features, as you had to add new route for every such thing. We currently have like 25 custom routes. You can never tell what the hack the url is because standard-url likeproducer/index
is routed from something likeproducers
.If you still want it, follow Marcin's answer :)