2

I thought that both types would bring you to the root folder, but apparently, they work differently, once you do a URL rewrite.

For instance, I normally use / which I know will bring you to the root folder and it does when a URL has been rewritten.

When someone else tried to use ~/ after a URL has been rewritten, then the path fails to find the file. Why is that?

Anna
  • 239
  • 1
  • 7
  • 21

1 Answers1

4

/ will take you back to the root of your website.

~/ will take you to the home folder of your application on the website.

If your application is in a folder called myApp, for example, so the URL looks like this

http://www.YourSite.com/myApp/ 

and in your application you use ~/Scripts/jquery.js then the path referenced will be

http://www.YourSite.com/myApp/Scripts/jquery.js

whereas just using / would send you all the way back to the root of the website

http://www.YourSite.com/Scripts/jquery.js
Andrew S
  • 86
  • 7
  • 2
    Note that the `~/` URLs will only work when processed by ASP.NET. You can call [`ResolveUrl`](http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl.aspx) on that URL, or use it in an `` or ``, but just adding a `~/` URL into regular HTML isn't going to be transformed into the correct URL. That is, the browser doesn't know anything about `~/` URLs, and won't be able to resolve them to the intended resource. – bdukes Oct 26 '12 at 13:28