如何在用户可以通过在末尾添加 / 来从浏览器调用文件的情况下链接相对的 html 文件
(抱歉,我无法正确提出问题。)
以下是场景。
我有 2 个 Html 文件。
File1.Html 有
<a href="File2.html">Click Me</a>
File2.Html
<a href="File1.html">Click Me</a>
现在当我在浏览器中打开 file1.html 时,在浏览器中键入以下内容。
http://Localhost/File1.html
显示带有链接的 file1.html,单击后它会转到
http://Localhost/File2.html
“但
如果我通过在浏览器中键入以下内容在浏览器中打开 file1.html(请注意末尾的 / )”。
http://Localhost/File1.html/
显示带有链接的 file1.html,单击它时,它会转到
http://Localhost/File1.html/File2.html
我知道这不是在浏览器中执行此操作的正确方法,但您无法阻止用户这样做。
我使用上面的例子只是为了简化问题。我真正的生产问题是使用 MVC url 时实际路由的。因此用户可以合法地使用 http://example.com/Employee 或 http://example.com/Employee/ 因此我的 jqGrid 无法工作。
请指导我找到解决方法。
更新: 这在 IExplorer 中工作正常:奇怪。
(Sorry I am not able to frame question correctly.)
Following is the scenario.
I have 2 Html files.
File1.Html has
<a href="File2.html">Click Me</a>
File2.Html has
<a href="File1.html">Click Me</a>
Now when I open the file1.html in browser by typing following in browser.
http://Localhost/File1.html
The file1.html with a link is shown and when clicked it goes to
http://Localhost/File2.html
BUT
If I open the file1.html in browser by typing following in browser(note the / at the end).
http://Localhost/File1.html/
The file1.html with a link is shown and when clicked it goes to
http://Localhost/File1.html/File2.html
I know this is not a right way to do in browser but you cant stop user doing so.
The above example I have used just to simplify the issue. My real production issue issue is while using the MVC url are actually routed. So a user can legally use http://example.com/Employee Or http://example.com/Employee/ and due to this my jqGrid is not working.
Please guide me for a workaround.
UPDATE:
This works ok in IExplorer : wierd.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要一个相对于根的链接。以下内容:(
请注意 href 开头的“/”)将链接到 http://Localhost/File1.html 包含链接的页面所在的位置(只要它位于同一主机上)。
You want a link relative to the root. The following:
(note the '/' at the start of the href) will link to http://Localhost/File1.html wherever the page containing the link is (so long as it's on the same host).
这是不可能的。如果您使用路由 URI,则基本名称后面可能有各种 /path/segment。浏览器无法知道真正的“父级”是什么。
通常的解决方案是按照 Joe 的建议使用根相对 URI。如果您需要允许应用程序安装在根目录下的可配置前缀处,则需要将该前缀复制到链接中。
That's not possible. If you are using routed URIs there can be all sorts of /path/segments following the base name. The browser has no way of knowing what the real ‘parent’ is.
The usual solution is to use root-relative URIs as suggested by Joe. If you need to allow your application to be mounted at a configurable prefix under the root, that prefix will need to be copied out into the link.
你的问题让我想起了一种用 PHP 实现的搜索友好 URL 技术。
例如:
在 Sitepoint.com 上描述了这个想法index.php 可以从 Web 服务器检索 URL 的尾部部分并决定如何处理它。包括是否处理final/或not。
它与 html 文件无关(毕竟它无法检索 URL 的尾部部分),但它可能提供进一步的想法。
Your question reminds me of a technique for search friendly URLs, implemented in PHP.
Things like:
It was described on Sitepoint.com The idea was that index.php could retrieve the trailing part of the URL from the web server and decide what to do with it. Including whether to deal with a final / or not.
It won't be relevant to html files (which could not, after all, retrieve the trailing part of a URL) but it might provide further ideas.