title: Proper way to encode a (relative) URL using PHP
body: <p>I'm trying to encode the following relative URL using PHP:</p>
  
  <pre><code>/tracks/add/5449326
  </code></pre>
  
  <p>I've tried using rawurlencode and urlencode.</p>
  
  <p>Which made it look something like: <code>%2Ftracks%2Fadd%2F5449326</code></p>
  
  <p>I'm going to use this URL in an AJAX call.</p>
  
  <p>The URL I am trying to make the call to is:</p>
  
  <pre><code>/overlay/add-track/{param1}/{param2}
  </code></pre>
  
  <p>{param1} is just some id</p>
  
  <p>{param2} is the encoded url</p>
  
  <p>However when I try to make the call I get a 404.</p>
  
  <p>From the looks of it, it is trying to make a call to:</p>
  
  <pre><code>/overlay/add-track/1//tracks/add/5449326
  </code></pre>
  
  <p>So it looks like it's trying to access the decoded string.</p>
  
  <p>Any ideas how to fix this?</p>
  
  <p>PHP</p>
  
  <pre><code>$url = rawurlencode('/tracks/add/5449326');    
  echo '&lt;a href="/overlay/add-track/1/'.$url.'"&gt;Add&lt;/a&gt;';
  </code></pre>
  
  <p>JS (jQuery)
      var href = $('a').attr('href');</p>
  
  <pre><code>$.ajax({
    url: href,
    type: 'POST',
    data: {},
    dataType: "json",
    success: function(data)
    {
      // do stuff
    }
  });
  </code></pre>
  
  <p>EDIT</p>
  
  <pre><code>  RewriteEngine on
  
    RewriteCond %{REQUEST_FILENAME} \.(eps|js|ico|gif|jpg|png|css|jpeg|doc|xls|doc|pdf|txt|ppt|zip)$
    RewriteRule ^(.*)$ $1 [L]
  
    RewriteCond "/path/public/%{REQUEST_URI}" !-f
    RewriteRule ^(.*)$ /index.php/$1 [L]
  </code></pre>