Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with URL encoded parameters in URL view helper
    text
    copied!<p>So my problem is kinda weird, it only occurs when I test the application offline (on my PC with WampServer), the same code works 100% correctly online.</p> <p>Here is how I use the helper (just example):</p> <pre><code>&lt;a href="&lt;?php echo $this-&gt;url(array('module' =&gt; 'admin', 'controller' =&gt; 'index', 'action' =&gt; 'approve-photo', 'id' =&gt; $this-&gt;escape($a-&gt;id), 'ret' =&gt; urlencode('admin/index/photos')), null, true); ?&gt;" class="blue"&gt;approve&lt;/a&gt; </code></pre> <p>Online, this link works great, it goes to the action which looks similar to this:</p> <pre><code>public function approvePhotoAction() { $request = $this-&gt;getRequest(); $photos = $this-&gt;_getTable('Photos'); $dbTrans = false; try { $db = $this-&gt;_getDb(); $dbTrans = $db-&gt;beginTransaction(); $photos-&gt;edit($request-&gt;getParam('id'), array('status' =&gt; 'approved')); $db-&gt;commit(); } catch (Exception $e) { if (true === $dbTrans) { $db-&gt;rollBack(); } } $this-&gt;_redirect(urldecode($request-&gt;getParam('ret'))); } </code></pre> <p>So online, it approves the photo and redirects back to the URL that is encoded as "ret" param in the URL ("admin/index/photos").</p> <p>But offline with WampServer I click on the link and get 404 error like this:</p> <pre><code>Not Found The requested URL /public/admin/index/approve-photo/id/1/ret/admin/index/photos was not found on this server. </code></pre> <p>What the hell?</p> <p>I'm using the latest version of WampServer (WampServer 2.0i [11/07/09]). Everything else works.</p> <p>Here is my .htaccess file, just in case:</p> <pre><code>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 </code></pre> <p>I'm using virtual hosts to test ZF projects on my local PC. Here is how I add virtual hosts.</p> <p>httpd.conf:</p> <pre><code>NameVirtualHost *:80 &lt;VirtualHost *:80&gt; ServerName myproject DocumentRoot "C:\wamp\www\myproject" &lt;/VirtualHost&gt; </code></pre> <p>the hosts file:</p> <pre><code>127.0.0.1 myproject </code></pre> <p>Any help would be appreciated because this makes testing and debugging projects on my localhost a nightmare and almost impossible task. I have to upload everything online to check if it works :(</p> <p>UPDATE:</p> <p>Source code of the _redirect helper (built in ZF helper):</p> <pre><code>/** * Set redirect in response object * * @return void */ protected function _redirect($url) { if ($this-&gt;getUseAbsoluteUri() &amp;&amp; !preg_match('#^(https?|ftp)://#', $url)) { $host = (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:''); $proto = (isset($_SERVER['HTTPS'])&amp;&amp;$_SERVER['HTTPS']!=="off") ? 'https' : 'http'; $port = (isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:80); $uri = $proto . '://' . $host; if ((('http' == $proto) &amp;&amp; (80 != $port)) || (('https' == $proto) &amp;&amp; (443 != $port))) { $uri .= ':' . $port; } $url = $uri . '/' . ltrim($url, '/'); } $this-&gt;_redirectUrl = $url; $this-&gt;getResponse()-&gt;setRedirect($url, $this-&gt;getCode()); } </code></pre> <p>UPDATE 2:</p> <p>Output of the helper offline:</p> <pre><code>/admin/index/approve-photo/id/1/ret/admin%252Findex%252Fphotos </code></pre> <p>And online (the same):</p> <pre><code>/admin/index/approve-photo/id/1/ret/admin%252Findex%252Fphotos </code></pre> <p>UPDATE 3:</p> <p>OK. The problem was actually with the virtual host configuration. The document root was set to C:\wamp\www\myproject instead of C:\wamp\www\myproject\public.</p> <p>And I was using this htaccess to redirect to the public folder:</p> <pre><code>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] </code></pre> <p>Damn it I don't know why I forgot about this, I thought the virtual host was configured correctly to the public folder, I was 100% sure about that, I also double checked it and saw no problem (wtf? am I blind?).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload