[英]What is the difference between / and ~/ relative paths?
I thought that both types would bring you to the root folder, but apparently, they work differently, once you do a URL rewrite. 我以为这两种类型都会将您带到根文件夹,但是显然,一旦您重写URL,它们的工作方式就会不同。
For instance, I normally use / which I know will bring you to the root folder and it does when a URL has been rewritten. 例如,我通常使用/,我知道它将带您到根文件夹,并且在URL重写后也可以。
When someone else tried to use ~/ after a URL has been rewritten, then the path fails to find the file. URL重写后,当其他人尝试使用〜/时,则路径无法找到该文件。 Why is that?
这是为什么?
/ 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 例如,如果您的应用程序位于名为myApp的文件夹中,则URL如下所示
http://www.YourSite.com/myApp/
and in your application you use ~/Scripts/jquery.js then the path referenced will be 在您的应用程序中使用〜/ Scripts / jquery.js,则引用的路径将为
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.