duanli8391 2010-02-11 18:05
浏览 42
已采纳

Zend_Router ... Zend_Form ... Mod_Rewrite ...将URL获取值重写为斜杠

I am submitting a normal <form method="get"> element to the current url... It's part of a search page. The resulting url is below.
http://domain.com/module/controller/action/get1/value1/?get2=get2&value3=value3
The problem is I am using <?= $this->url(array('page' => x)); ?> and similar to navigate around but I want to retain the $_GET params... Whenever I use it, it retains the / slashed $_GET params and looses the ?&= value pairs...
I want to use Mod_Rewrite to change the value pairs to slashes... My current rule is..

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ zend.php [NC,L]

I'm not confident with Mod_Rewrite and I don't want to conflict with the existing rules.

I also like a trailing slash as well... so that would be a bonus...

Please help!! Many thanks...

PS... Re "Zend_Router... Zend_Form.." in the title. I am using Zend_Form to construct the form and I realise that I could use javascript on the onSubmit function to write the URL... similarly I could use the Zend_Router to rewrite the url... I think Mod_rewrite is best though...

  • 写回答

2条回答 默认 最新

  • douqiangchuai7674 2010-02-20 16:47
    关注

    I could not find a nice way to do this... so I resolved to write some minimised PHP code at the top of my zend.php.

    list($sURL, $sQuery) = explode('?', $_SERVER['REQUEST_URI']);
    $sOriginalURL = $sURL;
    if ('/' !== substr($sURL, -1)) $sURL .= '/';
    if (isset($sQuery)) {
        foreach (explode('&', $sQuery) as $sPair) {
            if (empty($sPair)) continue;
            list($sKey, $sValue) = explode('=', $sPair);
            $sURL .= $sKey . '/' . $sValue . '/';
        }
    }
    if (isset($sQuery) || $sOriginalURL !== $sURL) header(sprintf('Location: %s', $sURL));
    

    If anyone can improve on this please comment below.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b