views:

129

answers:

2

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&amp;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...

A: 

I do not know how to implement this, using regular expressions and mod_rewrite, but you can extend Zend_Controller_Router_Route like this and use it instead standard router:

<?php
class ZendY_Controller_Router_Route_GetAware extends
        Zend_Controller_Router_Route
{
    public static function getInstance(Zend_Config $config)
    {
        $reqs = ($config->reqs instanceof Zend_Config)
                ? $config->reqs->toArray() : array();
        $defs = ($config->defaults instanceof Zend_Config)
                ? $config->defaults->toArray() : array();
        return new self($config->route, $defs, $reqs);
    }

    public function match($path)
    {
        foreach ($_GET as $k => $v) {
            if (is_array($v)) {
                $v = implode(',', $v);
            }
            $path .= "{$this->_urlDelimiter}{$k}{$this->_urlDelimiter}{$v}";
        }
        parent::match($path);
    }
}
Vladimir
A: 

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.

Simon