Zend Framework 2 重写 URL [英] Zend Framework 2 Rewrite URL

查看:31
本文介绍了Zend Framework 2 重写 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Zend Framework 2 应用程序,我希望使用 .htaccess 来重写一些 URL..htaccess 文件在我的公共文件夹中.我已经验证了一个简单的重写规则,它将所有的 testurl 重写为 test.php

I have a Zend Framework 2 app and I wish to use .htaccess to rewrite some URLs. The .htaccess file is in my public folder. I have verified a simple rewrite rule which rewrites all testurl to test.php

RewriteRule ^testurl/?$ test.php [NC]

test.php 文件也在 public 文件夹中.我将此规则置于 Zend 规则之上,以将所有 URL 映射到 .htaccess 中的 index.php.

The test.php file is also in the public folder. I placed this rule above the Zend rule to map all URLs to index.php in .htaccess.

我的问题是如何重写它以表示索引模块中的 SearchController?我尝试了各种不同标志的重写规则,例如

My question is how do i rewrite this to say the SearchController in the Index Module? I have tried various rewrite rules with different flags such as

RewriteRule ^testurl/?$ /index/search [NC]
and
RewriteRule ^testurl/?$ index/search [NC]

但我总是收到 404 错误请求的 URL 无法通过路由匹配.

but i always get the 404 error The requested URL could not be matched by routing.

我希望使用 .htaccess 的原因是我将在重写规则中使用正则表达式来捕获几个不同的 URL.

The reason i wish to use .htaccess is that i'll be using a regex in the rewrite rule to catch a few different URLs.

非常感谢

推荐答案

你要么想要:

RewriteRule ^testurl/?$ /index/search [NC,L,R]

或者你需要在 Zend 中为 testurl 添加一个路由并路由到 SearchController.

Or you need to add a route for testurl in zend and route it to the SearchController.

这篇关于Zend Framework 2 重写 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆