.htaccess Url重写删除查询字符串键

Ash*_*wal 5 php .htaccess zend-framework url-rewriting

我有一套像...的网址

www.example.com/page/1/name/abc
www.example.com/city/la/name/abc
www.example.com/page/1/name/abc/city/la
www.example.com/page/1/
Run Code Online (Sandbox Code Playgroud)

并希望将它们转换为..

www.example.com/1/abc
www.example.com/la/abc
www.example.com/1/abc/la
www.example.com/1/
Run Code Online (Sandbox Code Playgroud)

基本上我想隐藏查询字符串中的键.

这该怎么做?任何帮助?

编辑

每个页面都有不同的键,每页大约有25个键.

Mak*_*s3w 4

您可以使用Zend_Controller_Router_Route和/或Zend_Controller_Router_Route_Regex并定义路由

$route = new Zend_Controller_Router_Route(
    ':key/:city_name',
    array(
        'controller' => 'somecontroller',
        'action'     => 'pageAction'
    ),
    array('key' => '^\d+$')
);
$router->addRoute('page', $route); // www.example.com/1/abc

$route = new Zend_Controller_Router_Route(
    ':key/:city_name',
    array(
        'controller' => 'somecontroller',
        'action'     => 'cityAction'
    ),
    array('key' => '^\d+\w+$') // www.example.com/1a/abc
);
$router->addRoute('city', $route);
Run Code Online (Sandbox Code Playgroud)

  • 除非我弄错了,否则这并不能解决他的问题,即他想首先实际重写 URL……但这将提供解释重写 URL 的解决方案。 (2认同)