title: Htaccess redirect single file 301
body: <p>I have changed a file name and I want to create a permanent redirect (301).</p>
  
  <p>My .htaccess file is in a subdirectory (<a href="http://example.com/js" rel="nofollow">http://example.com/js</a>)</p>
  
  <p>I want to redirect <a href="http://example.com/js/oldfilename.js" rel="nofollow">http://example.com/js/oldfilename.js</a></p>
  
  <p>to <a href="http://example.com/js/newfilename.js" rel="nofollow">http://example.com/js/newfilename.js</a></p>
  
  <p>With this code, the redirect works:</p>
  
  <pre><code>RewriteEngine On
  RewriteRule ^oldfilename.js$ newfilename.js [L]
  </code></pre>
  
  <p>But the URL is not rewritten. When I change <code>[L]</code> to <code>[L,R=301]</code> the URL is rewritten but is broken. The rewritten URL seems to be the http host (<a href="http://example.com" rel="nofollow">http://example.com</a>) followed by the absolute path to the file in the filesystem. </p>