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条)

报告相同问题?

悬赏问题

  • ¥20 数学建模数学建模需要
  • ¥15 c语言数据结构实验单链表的删除
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决