Zend Framework 2 Rewrite URL

2019-03-04 12:11发布

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]

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.

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]

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

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.

Many thanks

1条回答
The star\"
2楼-- · 2019-03-04 12:48

You either want:

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

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

查看更多
登录 后发表回答