简体   繁体   中英

Zend Framework 2 Rewrite URL

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM