Url without a file name

I saw URLs like website.com/admin/ that did not actually display "index.html" or the file name after the last slash. How is this achieved?

Thanks!

+4
source share
10 answers

The URL indicates the location of the resource, but this resource does not have to be displayed on a physical file on the server. This is the server to decide how to handle the URL and how to generate the returned resource.

Most web servers started by serving all the resources from files. Thus, most websites where their pages served as files, and the URLs that they recognize, have the corresponding form. If the website still uses a file-based web server, you can configure it to serve a specific document by default if the file is not specified.

Recently, however, there has been a great movement toward decoupling URLs and actual files. This is usually achieved using default documents (where the web server is configured to serve a specific file if no URL is specified), URL routing (where the web server directs request processing based on internal rules that display the incoming URL for actual resources), URL rewriting (when the URL is rewritten to another URL before processing), or a combination of both.

In particular, MVC structures rely heavily on URL routing, because the URLs represented by a web application based on the MVC structure do not determine the location of the file on the server, but in fact the code execution path for the Internet application. For example, http://example.org/user/details/12345 will not indicate the 12345 file in the / user / details folder, but will indicate that the Details method in the User class should be called with parameter 12345 to generate a response.

+8
source

The web server configuration maps the resource URL. Most often, a file like index.HTML or index.php, but it does not have to be a file - the web server can be configured to serve the default index (or any other URL), returning the contents of the generated module or cgi. There is no need for a one-time mapping between URLs and files.

+2
source

Most web servers have a configuration option that allows the administrator to install one or more files to search if a file name is not found. Often they also allow you to set this in a directory at the directory level.

Another possibility, depending on the site, is that it uses technology to convert (aka "rewrite") the URL on the fly, so the URLs entered by the user are more meaningful to the user. This method is common for sites built using MVC templates.

+1
source

In such situations, the web server rewrites the URL into a real file (usually "index.html" or "default.html").

+1
source

It depends on the setting of your http server (apache ...). It, for example, will automatically load your index.php if it exists in the directory.

EDIT:

With this setting, your browser will not change the address http://site.com/ to http://site.com/index.html

+1
source

In addition to the default file (index.html, default.htm, default.aspx, ...), most web servers allow you to rewrite URLs, which means that you can match any URL on any resource. See Apache module mod_rewrite, either an application and request routing application, or ISAPI rewrite modules.

+1
source

Maybe this document is configured by default or the website uses MVC.

0
source

Besides the fact that the web server makes some bewilderment for the name of the machine’s file, it may turn out that its own application is working there, which processes the URLs independently. A URL is just a URL, matching it 1: 1 with a file name is just one way to do this.

0
source

There are at least three different ways ...

0
source

Since we have no answer for the opponent, this is:

Most web servers look for the index.html index file. What you see as /admin is a directory or "folder". So what you need to do is create a folder with your web host and put your files there, be sure to rename the file you want to display when you go to /Whatever to index.html ...

0
source

Source: https://habr.com/ru/post/1304108/


All Articles