开发者

url without file name

开发者 https://www.devze.com 2022-12-23 11:23 出处:网络
I have seen urls like webs开发者_JAVA技巧ite.com/admin/ that don\'t actually show the \"index.html\" or file name after the last slash. How is this achieved?

I have seen urls like webs开发者_JAVA技巧ite.com/admin/ that don't actually show the "index.html" or file name after the last slash. How is this achieved?

Thank you!


A URL specifies the location of a resource, but that resource does not have to actually map to a physical file on the server. It's up to the server to decide how to process the URL and how to generate the resource to return.

Most webservers started by serving all the resources from files. Thus, most of the websites out there have their pages served as files, and the URLs they recognize have the corresponding form. If the website is still using a file-based webserver, it is possible to configure it to serve particular document by default, if a file is not specified.

However, lately, there's a big movement towards decoupling of the URLs and the actual files. Usually this is achieved through default documents (where the webserver is configured to serve specific file if the URL does not specify one), URL routing (where the webserver routes the request processing based on internal rules that map the incoming URL to the actual resources), URL rewriting (where the URL request is rewritten to a different URL before processing), or a combination of both.

In particular, the MVC frameworks rely a lot on the URL routing, as the URLs exposed by a web app based on an MVC framework specify not the location of a file on the server, both actually the code execution path for the web app. For example http://example.org/user/details/12345 would not specify the 12345 file in the /user/details folder, but would specify that the method Details on the class User should be invoked with parameter 12345 to generate the response.


The web server's configuration maps the URL to a resource. Most often that's a file such as index.HTML or index.php, but there doesn't have to be a file--the web server could be configured to serve the default index (or any other URL) by returning content generated by a module or cgi. There is no requirement for a one-to-correspondance between urls and files.


There is a configuration option on most web servers that allow the administrator to set one or more files to look for if the file-name isn't found. Often, they also let you set this on a directory by 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 technique is common for sites built using the MVC templates.


The webserver re-writes the URL to a real file (usually "index.html" or "default.html") in such situations.


In addition to the default file (index.html, default.htm, default.aspx, ...) most webservers allow URL rewriting which means you can map any URL onto any resource. See Apache module mod_rewrite, or Windows Application and Request Routing, or ISAPI rewrite modules.


It depend on your http server (apache...) setting. It will for example automatically load your index.php if one exist in the directory.

EDIT:

By doing such setting, your browser will not change the address from http://site.com/ to http://site.com/index.html


It could be that default document is configured or the website is using MVC.


Apart from the webserver doing some automagic file name guessing, it may be that there's a custom application running that handles URLs by itself. A URL is just a URL, mapping it 1:1 to a file name is just one way to do it.


There are at least three different ways...

  1. Use Default Documents
  2. Use URL Rewriting
  3. Use MVC


Since no one has a propper answer here it is:

Most webservers look for an index file index.html. What you see as /admin is a directory or "folder". So what yo must do is make a folder with your webhost and place your files in there, make sure to rename the file to want to display when you navigate to /Whatever to index.html...

0

精彩评论

暂无评论...
验证码 换一张
取 消