-1

(对不起,我无法正确地提出问题。)

以下是场景。

我有 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/Employeehttp://example.com/Employee/,因此我的 jqGrid 无法正常工作。

请指导我解决方法。

更新:这在 IExplorer 中可以正常工作:奇怪。

4

3 回答 3

2

你想要一个相对于root的链接。以下:

<a href="/File1.html">Click Me</a>

(注意 href 开头的“/”)将链接到http://Localhost/File1.html包含链接的页面所在的任何位置(只要它位于同一主机上)。

于 2009-09-14T12:05:04.827 回答
0

不相对于根我需要它相对于父

那是不可能的。如果您使用的是路由 URI,则在基本名称之后可以有各种 /path/segments。浏览器无法知道真正的“父母”是什么。

通常的解决方案是使用 Joe 建议的根相对 URI。如果您需要允许将应用程序安装在根目录下的可配置前缀,则需要将该前缀复制到链接中。

于 2009-09-14T12:46:38.953 回答
0

Your question reminds me of a technique for search friendly URLs, implemented in PHP.

Things like:

http://localhost/index.php/2009/09/

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.

于 2009-09-14T12:53:04.917 回答