Zend 框架重新路由以实现友好的 SEO URL?

发布于 2024-12-20 17:49:14 字数 528 浏览 1 评论 0原文

我什至不明白从哪里开始使用文档及其说明。有点傻眼。

我有网址: http://www.site.com/test/view/?aid=155" rel="nofollow">http://www.site.com/test/view/?现在援助=155

我希望它显示为 http://www.site.com/test/155 (使用控制器“测试”和操作“视图”,参数辅助为 155)

,对于未来的学习经验,我会如何做 http://www.site.com/madeupname/155

我该从哪里开始?什么文件?

我在里面放什么?

请并谢谢你们!!!!

I don't even understand where to start using the documentation and it's instructions. A little dumbfounded.

I have the URL : http://www.site.com/test/view/?aid=155 right now.

I want it to show up as http://www.site.com/test/155 (Using controller "test" and action "view" with parameter aid as 155)

and for future learning experiences, how would I do http://www.site.com/madeupname/155

Where would I start? What file?

What do I put in it?

Please and thank you!!!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木緿 2024-12-27 17:49:14

这并不难做到,特别是当您使用 .ini 文件作为路线时。
在/site/application/configs 文件夹中创建一个routes.ini 文件。

例如:

[production]
routes.home.route = /home/
routes.home.defaults.controller     = index
routes.home.defaults.action         = index

routes.login.route = /login/:username/:password
routes.login.defaults.controller    = index
routes.login.defaults.action        = login
routes.login.defaults.username      = username
routes.login.defaults.password      = password

然后引导它

(在 bootstrap.php 中添加此内容)

   /*
     * Initialize router rewriting via .ini file.
     */
    protected function _initRewrite()
    {
        $router = Zend_Controller_Front::getInstance()->getRouter();
        $router->addConfig(new Zend_Config_Ini(APPLICATION_PATH. "/configs/routes.ini",
                'production'), 'routes');
    } 

然后您可以使用 www.site.com/login/yourname/yourpass 访问登录页面

或通过 www.site.com/home 访问主页

< a href="http://www.devpatch.com/2010/02/load-routes-from-routes-ini-config-file-in-zend-application-bootstrap/" rel="nofollow">http://www.devpatch.com/2010/02/load-routes-from-routes-ini-config-file-in-zend-application-bootstrap/

http://framework.zend.com/manual/en/zend.controller.router.html

It's not that hard to do, especially if you use an .ini file for your routes.
Create a routes.ini file inside of your /site/application/configs folder.

For example :

[production]
routes.home.route = /home/
routes.home.defaults.controller     = index
routes.home.defaults.action         = index

routes.login.route = /login/:username/:password
routes.login.defaults.controller    = index
routes.login.defaults.action        = login
routes.login.defaults.username      = username
routes.login.defaults.password      = password

and then bootstrap it

(inside bootstrap.php, add this)

   /*
     * Initialize router rewriting via .ini file.
     */
    protected function _initRewrite()
    {
        $router = Zend_Controller_Front::getInstance()->getRouter();
        $router->addConfig(new Zend_Config_Ini(APPLICATION_PATH. "/configs/routes.ini",
                'production'), 'routes');
    } 

You could then access the login page with www.site.com/login/yourname/yourpass

or get to the home page via www.site.com/home

http://www.devpatch.com/2010/02/load-routes-from-routes-ini-config-file-in-zend-application-bootstrap/

http://framework.zend.com/manual/en/zend.controller.router.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文