title: Add trailing slash to url
body: <p>I'm trying to add a trailing slash to urls using PHP. It can't be done with mod_rewrite since I have something similar to this in .htaccess:</p>
  
  <pre><code>RewriteRule ^page/(.*)$ index.php?page=$1 [L]
  </code></pre>
  
  <p>and I want to validate that the page exists before 301 redirect with trailing slash.</p>
  
  <p>Right now I'm using this code after validation:</p>
  
  <pre><code>if(substr($_GET['page'], -1) !== '/')
    header('Location: http://example.com/'.$_GET['page'].'/'.$_SERVER['QUERY_STRING'],TRUE,301);
  </code></pre>
  
  <p>But is there any better approach?</p>