Using a tilde in a url after a forward slash - html

I've come across a background image reference of this form in some HTML code I'm changing.
<a style="background: url('/~/media/Images/Shared/Logos/logo.png')" href="/">Home</a>
I'm not in a position to ask the original author, and I don't understand how the tilde is being evaluated here.
If the url string started "url('~/media/.....'" I understand would be the root of the media user (so you'd better be sure you create that user on all your deployment servers) but the / in front of the tilde has me confused.
All the searches I've done just bring back the home directory explanation, but it doesn't appear to be that.
[edit] This is part of a live site, the logo shows up correctly, I just don't know why.
[edit 2] The site is built using ASP.NET.
[edit 3] The above is a cleaned version of the url from a view/source on the site, not the ASP code.
[edit 4] For those that might be curious, here's the actual working url. I work for the same company, but a different division, and I'm building an internal support tool in Java EE which is borrowing some of the styling. I saw the "/~/...." and couldn't think of a good reason why it would work.
http://business.hibu.co.uk/~/media/Images/Shared/Logos/logo.png

In ASP.NET, a tilde represents the root of the application (not necessarily the root of the website). But it's only usable in certain circumstances (server controls, controls that are data-bound, or sometimes tags in the head section like script or link).
I wouldn't think an a tag in the regular body would handle it, and I don't think ASP.NET allows the tilde to go anywhere except the beginning of the string anyway.
So I'm guessing you simply actually have a physical directory named ~. In Windows, I don't think the tilde has any special meaning, so it's not the user's home directory or anything like that - just a funky name for a regular directory.
EDIT
After reading your comment that this is the way it's rendered in the browser, and it's working, I'm almost positive that there's a real directory called ~ on your web server. Either that or some kind of URL rewriting going on, which you'd need to see the web.config or IIS settings to see that.

That's likely from their local machine, meaning their home directory. It can never resolve properly from a remote server if the asset path was copied from their development machine.
Otherwise it's a path relative to the home directory on their server.

Related

PDF link not working on webpage

Ok so I have a intranet webpage that I am making using HTML and I want to put a link (absolute or relative) on my page that opens a PDF.
The code I use is
Privacy and Security
Now what ends up happening is that I get this error:
404 - File or directory not found. The resource you are looking for
might have been removed, had its name changed, or is temporarily
unavailable.
Is there anything wrong with my code or where I am placing the document?
Thank You
If you are running this on a local machine check the permissions on the PDF file that they are world readable. I have this happen a lot in my OS X web directory, some files dragged in seem to have different permissions.
I see a number of small... oddities... in your sample line, which may or may not be significant in themselves, but could cause problems if you're doing any post-processing of the line before it goes live.
http://harold.local/documents/sandP.pdf is a good destination, correct? If you drop that by itself in to the address line of your browser, you can confirm that the PDF document can be found and displayed?
If you're doing any further processing of that string, should you be escaping the slashes or backslashes by doubling each one?
There's a stray space between your target= argument and your _blank value, again a possible risk if something later on will attempt to parse the string.
There is what appears to be a stray Left Angle Bracket (or Less Than) symbol ("<") immediately in front of your Privacy and Security text, which could be misinterpreted as the start of a <p tag, probably not what you want.
I would start by verifying the destination, then adding the context around it a bit at a time until something breaks. Failing that, find a similar working example of the <a usage on your local machine, and use that as a starting point for the link to your sandP.pdf document.

How to make working path in HTML?

So, currently I'm making a website. It's an assignment. And when I tried to open it on different computer, it didn't work.
So, for example: "a href="file:///E:/assignment/main page/index.html#"
It did work on my computer, but it won't work on another. I need it to work at any computer.
There are two halves to your question:
How do I make my website accessible anywhere?
You need a web server, or you need to use a hosting company. GoDaddy, 1and1, HostGator, and other hosting companies have computers (web servers) that are configured to show their webpages to anyone in the world. They cost around $10 per month, and you end up with the ability to create links such as http://example.com/myproject/index.html
It's possible that your professor will let you put your web pages on one of his drives that are accessible anywhere on campus. Otherwise, a flash drive can do in a pinch. Put the files onto a flash drive and then bring the flash drive to class.
Is there a better way to write links?
Most websites use relative URLs in their links. For example, Stack Overflow, instead of writing every link as http://stackoverflow.com/whatever, will usually use a relative URL instead: /whatever.
There are a few simple rules that your browser follows when turning an href tag into a web address (in this example, we're starting from this page: http://stackoverflow.com/questions/15078748/how-to-make-working-path-in-html#15078792)
If the link starts with http:// (or anything else that comes before
a ://), then your browser will take you exactly there. For example:
http://stackoverflow.com takes you to the Stack Overflow home page.
If the link starts with /, then the browser will take you out of
any subfolders before executing the rest of the link. For example:
/election will take you here: http://stackoverflow.com/election
If the link starts with ../, then it will send you exactly one folder
up. This can be done multiple times. For example. ../ will send you
here: http://stackoverflow.com/questions/ .
If the link starts with a
question mark, ampersand, or hash tag, (?, &, #) then it will usually append
this to whatever page you are currently on. #example would take you
to
http://stackoverflow.com/questions/15078748/how-to-make-working-path-in-html#example
.
Finally, the browser will keep you in your current folder, then
send you to that link, for example: example will send you here:
http://stackoverflow.com/questions/15078748/example
You must use relative paths not absolute paths.
In simple words, you have to write:
...
to link to index.html a page which is in the same directory as your file index.html;
examples:
./my_page.html
use the "./" for linking pages in the same directory;
if the source and dest pages are in different folders, you shall use:
../my_page.html
or
./folder_path/my_page.html
according to the relative paths of the pages.

Relative path or url for html src and href attributes

Using a framework makes it easy to list full url's for my html src and href attributes, and I feel I'm being more thorough by listing a full url instead of a relative path. But is this faster? Am I incurring an extra DNS lookup? What is the best practice when the content is on the same server?
<img src='http://site.com/images/img1.png' />
vs
<img src='/images/img1.png' />
Codeigniter's image helper img() works like this from the users' guide:
echo img('images/picture.jpg');
// gives <img src="http://site.com/images/picture.jpg" />
and Codeigniter's anchor helper anchor() works like this from the users guide:
echo anchor('news/local/123','My News');
// gives <a href="http://example.com/index.php/news/local/123" >My News</a>
As far as DNS goes, it really doesn't matter if you have relative or absolute URL. Your browser ends up pre-pending the server URI onto the front anyway. Also, your network stack does the lookup for the first time, and caches the IP. Unless something goes wrong, there should only be the one lookup per page. YMMV of course, but that should be how this all works.
'Never' (alsmost never) use absolute paths.
It will bite you in the ass later.
For example when you switch / add another domain.
Go from your test to production server.
Basically the rule is internal URL's should be relative.
Oh you really don't want to use a full path. You'll have a lot of work ahead of you:
If you want to develop the site locally
You change / add domains (development, staging, etc)
You switch to using a CDN
You also will break your dev environment, since most modern ones will perform local directory lookups. Can't do that with a domain.
Also, in a dev environment you will be pulling from the production site, which will make modifying and adding images extremely tricky.
Most importantly, other developers working with your code will try to kill you. And that's bad for your health.
Portability would be the issue for me. I would choose the second option based on that alone.

How to link a relative html file in the scenario where user can call the files from the browser by adding a / at the end

(Sorry I am not able to frame question correctly.)
Following is the scenario.
I have 2 Html files.
File1.Html has
Click Me
File2.Html has
Click Me
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.
You want a link relative to the root. The following:
Click Me
(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).
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.
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.

File:// link doing nothing in all browsers

I have a link being generated that looks like so:
<a target="_blank" title="Test" href="file:///c:/test.xls">Test</a>
This link is inside an iframe.
When I click on it (in any major browser), nothing happens. Fiddler records no traffic.
Pasting the URL into the nav bar works fine - the file download box comes up, and I can download the file no problem.
I've tried every variant of the URL structure (correct and incorrect, colons, slashes, backslashes, etc.) that I can think of.
I'm certain that it's some kind of security restriction, but I can't for the life of me find out what it is or how to get around it. I'm feeling pretty foolish at this point. Any simple explanations?
Sorry, if you are pulling this page off of a server (acessing it as http://), the security settings won't let you link to local content (acess links as file://). I've had this same problem accessing shared .doc files in a wiki. Never came up with a good solution.
Try a colon instead of a pipe ;)