Is there a way, in html, to refer to the domain of a website without actually knowing it? - html

For example, I want a link to take the viewer to a folder on the website
Click here to go to this folder
But now I want to make it so that other developers can use my code on their website without having to personally edit it. Is there a way for me to reference the "http://www.Example.com" without actually knowing what the domain is?

If you simply want to make a relative link, i.e. a link relative to the current URL or domain, simply leave out the domain:
always goes to foo.html in the same folder as this document
always goes to /foo.html in the same domain
The same way you can also make a protocol relative URL:
goes to https://.. if current page is https, otherwise http

Related

How to make HTML href function to redirect the user to a world wide web page instead of a folder inside the user's computer?

I am learning HTML, and whenever I execute the href function in HTML and click the blue text, the browser tries to redirect me to a folder inside my computer, when in reality I want to enter a website. For example, if I try to execute the following code, instead of the browser redirecting me to duckduckgo.com, it tries to redirect me to a folder inside my computer:
Browse anonymously and without being traced
How can I solve this issue?
Because href="duckduckgo.com" is using a relative URL, so the browser is looking for duckduckgo.com relative to the current URL that is displaying the page. To the browser it's no different than if you used href="index.html", both are structurally identical.
Instead, use a fully-qualified URL:
Browse anonymously and without being traced
You can also default to the current protocol with this:
Browse anonymously and without being traced
So if the current page is open via http:// or https:// then the link would use the same in the resulting request. Note however that your description of "a folder inside my computer" may somewhat imply that your current protocol could be file://, in which case an inferred protocol clearly wouldn't work. The point is, the structure of a complete URL is pretty versatile so you have options.

Hide Url Show only Domain

How do I hide the full url path from one folder with html documents in it?
I did google this subject and did not found a working solution
i tried understanding the appache help files to re-write rules but it did not make sense to this newby
there are many links i found about url masking, but this is not what i need, i found many links about url beautifier, but thats also not what i need...
i like to hide the whole path in my url, and do not know if its possible with htaccess, or how to do it in a different way
i tried loading a iFrame into my page because that would hide my url path as well, but since i use mainly JavaScript, i did not find a solution to get from php a possibility to run a JavaScript function that adds an iFrame to my site.
i do have a php mail file when complete it opens a new thank-you html document
then the path and file name is visible of this document, that i want to learn how to hide
current url:
www.example.com/includes/html/thank-you.html
prefrered url:
www.example.com
You cannot hide the complete URL to a resource.
You can make http://example.com/ be the complete URL to a resource (the easiest way to do that is to call it index.html and put it in the DocumentRoot directory)), but then http://example.com/ is the complete URL to that resource and only that resource.
You can't have two (or more) different documents both at the URL http://example.com/.
What you are asking for is akin to taking all the house numbers off every house in a street.
Nobody would be able to visit you because nobody could tell which of the 50 hours in the street is the one they want.

How to mask a URL via HTML or .htaccess

I am setting up a website that I want no one to know the URL for. For example, I send them a link that actually goes to the page, but the URL in the bar at the top has a completely different URL that I don't own. I'm not sure if this can be done in PHP, HTML, or the .htaccess file.
This is not possible, unless
you control the systems of the visitors (then you could, for example, change their DNS servers), or
you find and exploit a bug in the browser/system.
You can make a link anchor text look like it leads to a specific domain not under your control, but the real URL will be used in any case. Example: http://wikipedia.org/.

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.

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.