Php URL视图帮助程序中的URL编码参数存在问题

Php URL视图帮助程序中的URL编码参数存在问题,php,zend-framework,Php,Zend Framework,所以我的问题有点奇怪,它只发生在我离线测试应用程序时(在我的装有WampServer的PC上),同样的代码100%正确地在线工作 以下是我如何使用帮助器(仅举一个例子): 因此,它在线批准照片并重定向回URL中编码为“ret”参数的URL(“admin/index/photos”) 但在WampServer离线时,我单击链接,得到404错误,如下所示: Not Found The requested URL /public/admin/index/approve-photo/id/1/ret/

所以我的问题有点奇怪,它只发生在我离线测试应用程序时(在我的装有WampServer的PC上),同样的代码100%正确地在线工作

以下是我如何使用帮助器(仅举一个例子):

因此,它在线批准照片并重定向回URL中编码为“ret”参数的URL(“admin/index/photos”)

但在WampServer离线时,我单击链接,得到404错误,如下所示:

Not Found

The requested URL /public/admin/index/approve-photo/id/1/ret/admin/index/photos was not found on this server.
怎么回事

我正在使用最新版本的WampServer(WampServer 2.0i[11/07/09])。其他一切都可以

这是我的.htaccess文件,以防万一:

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

# Turn off magic quotes
#php_flag magic_quotes_gpc off
我使用虚拟主机在本地PC上测试ZF项目。下面是我添加虚拟主机的方法

httpd.conf:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName myproject
    DocumentRoot "C:\wamp\www\myproject"
</VirtualHost>
任何帮助都将不胜感激,因为这使得在本地主机上测试和调试项目成为一场噩梦,几乎不可能完成。我必须在线上传所有内容,以检查其是否有效:(

更新:

_重定向帮助程序(内置ZF帮助程序)的源代码:

更新2:

脱机帮助程序的输出:

/admin/index/approve-photo/id/1/ret/admin%252Findex%252Fphotos
及网上(同):

更新3:

好的。问题实际上在于虚拟主机配置。文档根被设置为C:\wamp\www\myproject,而不是C:\wamp\www\myproject\public

我用这个htaccess重定向到公用文件夹:

RewriteEngine On

php_value upload_max_filesize 15M
php_value post_max_size 15M
php_value max_execution_time 200
php_value max_input_time 200
# Exclude some directories from URI rewriting
#RewriteRule ^(dir1|dir2|dir3) - [L]

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]
该死的,我不知道为什么我忘记了这一点,我认为虚拟主机已正确配置到公用文件夹,对此我100%确信,我也仔细检查了一遍,没有发现任何问题(wtf?我是瞎子吗?)

  • 检查您的php.ini
    php\u flag magic\u quotes\u gpc off
    必须在在线和本地服务器上
    off

  • 不要使用
    urlencode
    'ret'=>urlencode('admin/index/photos'))
    ,因为
    url
    helper有第四个参数
    $encode=true
    ,默认值为
    true

  • 显示服务器和本地主机上的
    $this->url(数组('module'=>'admin'..)的输出

  • 我在家里用wamp,效果很好

    更新1
    尝试
    $this->\u重定向('/'.ltrim(urldecode($request->getParam('ret')),'/');

    更新2

    视图脚本

        <a href="<?php
    
    echo $this->url(array('module' => 'default',
                      'controller' => 'index',
                      'action' => 'test-encoded-redirect',
                      'ret' => urlencode('default/static/faq')),
                null,
                true);
    
                            ?>">test me</a>
    
    
        <?php
        class IndexController extends Smapp_Controller_Action 
        {   
    
            public function testEncodedRedirectAction()
            {
    
                                // ddump($this->_getAllParams());
                // ddump output 
                // Array ( 
                //  [controller] => index 
                //  [action] => test-encoded-redirect 
                //  [ret] => default%2Fstatic%2Ffaq 
                //  [module] => default 
                // )
    
    
                $ret = '/' . ltrim(urldecode($this->_getParam('ret')), '/');
                // echo $ret;
                // output: /default/static/faq
    
                $this->_redirect($ret);
            }
        }
    
    
    
    你能发布$this->redirect的代码吗?$this->\u redirect是Zend框架中的内置帮助程序,但我在帖子中包含了来自ZF的源代码。看看我的
    默认%2Fstatic%2faq
    和你的
    /admin%252Findex%252Fphotos
    你的url编码了两次,但仍然有效。我没有时间去删除urlencode fr现在查看所有视图。这将需要几个小时,所以我将保持这样,以防将来它再次停止工作,我将只使用urldecode两次:)您可以编写ActionHelper来检查
    ret
    param是否存在-urldecode;)并在ActionController中编写并继续编写正确的代码。无需双重URL解码;)本地和web服务器上的魔法报价都已关闭。检查我文章的结尾。urlencode()不是问题所在。如果我把它处理掉,问题就会继续存在。另外,这是一个较旧的应用程序,我必须删除几十个视图中的urlencode()(在较旧的ZF版本中,第四个参数不在那里,我想他们确保了旧的ZF应用程序不会损坏。):)好的。显示
    echo ltrim(urldecode($request->getParam('ret')),“/”)
    输出它可能是
    baseUrl
    问题。因为最后一个链接应该在本地主机上看起来像
    /public/ret/admin/index/photos
    ,在服务器上看起来像
    /admin/index/photos
    ,如果是这样-你必须重新配置你的WAMP
    VirtualHost
    指向“DocumentRoot”C:\WAMP\www\myproject\public“`
    /**
     * Set redirect in response object
     *
     * @return void
     */
    protected function _redirect($url)
    {
        if ($this->getUseAbsoluteUri() && !preg_match('#^(https?|ftp)://#', $url)) {
            $host  = (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:'');
            $proto = (isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']!=="off") ? 'https' : 'http';
            $port  = (isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:80);
            $uri   = $proto . '://' . $host;
            if ((('http' == $proto) && (80 != $port)) || (('https' == $proto) && (443 != $port))) {
                $uri .= ':' . $port;
            }
            $url = $uri . '/' . ltrim($url, '/');
        }
        $this->_redirectUrl = $url;
        $this->getResponse()->setRedirect($url, $this->getCode());
    }
    
    /admin/index/approve-photo/id/1/ret/admin%252Findex%252Fphotos
    
    /admin/index/approve-photo/id/1/ret/admin%252Findex%252Fphotos
    
    RewriteEngine On
    
    php_value upload_max_filesize 15M
    php_value post_max_size 15M
    php_value max_execution_time 200
    php_value max_input_time 200
    # Exclude some directories from URI rewriting
    #RewriteRule ^(dir1|dir2|dir3) - [L]
    
    RewriteRule ^\.htaccess$ - [F]
    
    RewriteCond %{REQUEST_URI} =""
    RewriteRule ^.*$ /public/index.php [NC,L]
    
    RewriteCond %{REQUEST_URI} !^/public/.*$
    RewriteRule ^(.*)$ /public/$1
    
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^.*$ - [NC,L]
    
    RewriteRule ^public/.*$ /public/index.php [NC,L]
    
        <a href="<?php
    
    echo $this->url(array('module' => 'default',
                      'controller' => 'index',
                      'action' => 'test-encoded-redirect',
                      'ret' => urlencode('default/static/faq')),
                null,
                true);
    
                            ?>">test me</a>
    
    
        <?php
        class IndexController extends Smapp_Controller_Action 
        {   
    
            public function testEncodedRedirectAction()
            {
    
                                // ddump($this->_getAllParams());
                // ddump output 
                // Array ( 
                //  [controller] => index 
                //  [action] => test-encoded-redirect 
                //  [ret] => default%2Fstatic%2Ffaq 
                //  [module] => default 
                // )
    
    
                $ret = '/' . ltrim(urldecode($this->_getParam('ret')), '/');
                // echo $ret;
                // output: /default/static/faq
    
                $this->_redirect($ret);
            }
        }