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

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

问题描述

我有一个Zend框架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的文件也是在公共文件夹中。 我把这个规则之上的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错误 所请求的网址无法通过路由匹配。

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和路由到SearchController添加路由 testurl

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

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