title: 301 Redirect Preventing CORS OPTIONS Request on Openshift
body: <p>I'm writing a RESTful api with Laravel 4 that will be used by a Backbone.js app.</p>
  
  <p>When I deploy my code using GIT, I receive a message saying:</p>
  
  <blockquote>
    <p>Application directory "public/" selected as DocumentRoot</p>
  </blockquote>
  
  <p>When using the Backbone.js app, PUT, GET and DELETE requests are handled appropriately, but the preflight request (OPTIONS) fails because of the redirect when I try to make a POST request:</p>
  
  <blockquote>
    <p><strong>Request Method:</strong> OPTIONS<br/>
    <strong>Status Code:</strong> 301 Moved Permanently</p>
  </blockquote>
  
  <p>With this error on the console:</p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load <code>http://MY-DOMAIN.rhcloud.com/projetos/</code>. The request was redirected to <code>'http://MY-DOMAIN.rhcloud.com/projetos'</code>, which is disallowed for cross-origin requests that require preflight.</p>
  </blockquote>
  
  <p>This happens because of the CORS Policy:</p>
  
  <blockquote>
    <p><strong>If the response has an HTTP status code of 301, 302, 303, 307, or 308</strong><br/>
    Apply the cache and network error steps.</p>
  </blockquote>
  
  <p>How can I overcome this problem? Is there a way to bypass or configure the Openshift redirect?</p>
  
  <p><strong>>>>EDIT</strong></p>
  
  <p>I am getting this error on the Chrome javascript console, because my Backbone App is in development fase still. Here the steps to replicate the problem:</p>
  
  <p>I have a global namespace "App", and my project is organized in this form: App.Models, App.Collections, etc.</p>
  
  <p><strong>The Model</strong></p>
  
  <pre><code>App.Models.Projeto = Backbone.Model.extend({
  
      defaults : {
          codigo      : '',
          titulo      : '',
          url         : '',
          status      : ''
      }
  
  });
  </code></pre>
  
  <p><strong>The Collection</strong></p>
  
  <pre><code>App.Collections.Projetos = Backbone.Collection.extend({
  
      model : App.Models.Projeto,
  
      url : 'http://MY-DOMAIN.rhcloud.com/projetos'
  
  });
  </code></pre>
  
  <p><strong>On the Console</strong></p>
  
  <pre><code>var projetos = new App.Collections.Projetos;
  
  projetos.create({
      titulo : "blablabla",
      codigo : "12jk4h3",
      url    : "example.com",
      status : 0
  });
  </code></pre>
  
  <p>I am able to fetch, edit and delete models in the collection. The only thing I cannot do is to create a new one.</p>
  
  <p>One last thing, the URL I'm redirected to is the same URL, but without a "/" at the end. </p>
  
  <p>So even if the "url" property in the collection is set to <code>http://MY-DOMAIN.rhcloud.com/projetos</code> it seems like Backbone adds a "/", and then in the server, it gets redirected.</p>