title: ASP.NET MVC 4 Bundling and Minification: wrong paths in Debug Mode with Url Rewrite
body: <p>I want to use the <a href="http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification" rel="nofollow">ASP.NET MVC 4 Bundling and Minification</a> feature, please assume that we run the debug mode so nothing is bundled, but each reference is simply rendered to single tags. Locally everything works fine:</p>
  
  <p><strong>Example</strong></p>
  
  <pre><code> public static void RegisterBundles(BundleCollection bundles)
   {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));
   }
  </code></pre>
  
  <p>When calling <code>@Scripts.Render("~/bundles/jquery")</code> from the view now, a tag similar to this is generated:</p>
  
  <pre><code> &lt;script src="/Scripts/jquery-1.8.2.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>The result <strong>is the same</strong> if I would just write:</p>
  
  <pre><code> &lt;script src="@Url.Content("~/Scripts/jquery-1.8.2.js")"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>But when I deploy everything to a test server in the internet (still using the debug mode), there is some <strong>Url rewriting</strong> enabled, where I route specific domains or subdomains to specific folders.</p>
  
  <p>For example, if the domain is <code>sub1.example.com</code> then forward to <code>example.com/__sub1__</code> and in case of <code>sub2.example.com</code> forward to <code>example.com/__sub2__</code> and so on. When I open <code>sub1.example.com</code> in the browser, there is usually no clue that this forward happens, the Url doesn't change, all Urls remain working and so do references generated using the <code>Url.Content(...)</code> method.</p>
  
  <p>But for some strange reason, the call to <code>@Scripts.Render("~/bundles/jquery")</code> now renders something like this:</p>
  
  <pre><code> &lt;script src="/__sub1__/Scripts/jquery-1.8.2.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>Please note the "/<strong>sub1</strong>" part which is the part which shouldn't be generated and never appear somewhere in the rendered html code and leads to a 404 because the url rewrite forward fails.</p>
  
  <p>While...</p>
  
  <pre><code>&lt;script src="@Url.Content("~/Scripts/jquery-1.8.2.js")"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>...still renders the correct relative Path to "/Scripts/jquery-1.8.2.js". And i never had other problems with rewriting the Urls like this. And I don't want to get rid of this rewriting.</p>
  
  <p>Obviously, the same applies to style sheets.</p>
  
  <p>Any ideas what I could try?</p>