Zend框架2重写URL重写、框架、Zend、URL

2023-09-02 11:40:52 作者:菇凉你不要悲伤。

我有一个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