views:

60

answers:

3

(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.

+2  A: 

You want a link relative to the root. The following:

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

(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).

Joe
That’s called an absolute URL path.
Gumbo
not relative to root i need it relative to parent
Sachin
It's rooted, but not absolute as usually understood by that term (eg. RFC 2396)
bobince
you can use .. to ascend a directory, (e.g. <a href="../File1.html">Click Me</a>). Otherwise you cannot do this with plain HTML. Consider using a framework or design that allows you to give absolute paths in all cases.
Joe
@bobince: I think you rather mean an *absolute URL* but not *absolute URL path*.
Gumbo
A: 

not relative to root i need it relative to parent

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.

bobince
A: 

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.

pavium